where to download:
Oracle Website ODP.NET
How To Use:
//add reference Oracle.DataAccess to project //include Oracle.DataAccess using Oracle.DataAccess.Client; //create connection string string OraconnectionString = "user id=" + USERID + ";password=" + USERPASSWORD + ";" + "data source=(DESCRIPTION=(ADDRESS=" + "(PROTOCOL=tcp)(HOST=" + IPorSERVERNAME + ")" + "(PORT=1521))(CONNECT_DATA=" + "(SERVICE_NAME=" + ORACLESID + ")))"; //example Connection to DB OracleConnection OraConnection = new OracleConnection(OraconnectionString); try { OraConnection.Open(); } catch (OracleException err) { OraConnection.Close(); } finally { OraConnection.Close(); } //example insert/update/delete OracleCommand OraCommand = new OracleCommand("", OraConnection); if (OraConnection.State.ToString() == "Open") { try { //sql command OraCommand.CommandText = "insert into " + table + " (" + field + ") values (" + data + ")"; OraCommand.ExecuteNonQuery(); OraCommand = null; } catch (OracleException ex) { return ex.Message.ToString(); } } else { return "Oracle Connection Close"; } //example SQL select statement string strSQL = "select COLUMN_NAME from TABLE"; //assign connection and sql statement OracleCommand OraCommand2 = new OracleCommand(strSQL, OraConnection); //create data reader OracleDataReader OraDataReader = null; if (OraConnection.State.ToString() == "Open") { try { //execute data reader OraDataReader = OraCommand2.ExecuteReader(); //read SQL result while (OraDataReader.Read() == true) { OraDataReader["COLUMN_NAME"].ToString(); } OraDataReader.Close(); } catch (OracleException ex) { ex.Message.ToString(); } } else { return "Oracle Connection Close"; }
No comments:
Post a Comment