First, you need an oracle operation class, oradbhelper. cs. The Code is as follows:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. data; using system. data. oracleclient; /// <summary> /// abstract description of oradbhelper /// </Summary> public class oradbhelper {private string connectionstring; /// <summary> /// set the connection of the database string /// </Summary> Public String connectionstring {set {connectionstring = value ;}} public oradbhelper (string connectionstring) {This. Connectionstring = connectionstring;} # region executedatatable // <summary> // execute a query, and return the result set /// </Summary> /// <Param name = "commandtext"> the SQL text query command to be executed </param> /// <returns> query Result set </returns> Public datatable executedatatable (string commandtext) {return executedatatable (commandtext, commandtype. text, null) ;}/// <summary> /// execute a query, return the query result /// </Summary> /// <Param name = "commandtext"> the SQL statement to be executed </Param> /// <Param name = "commandtype"> type of the query statement to be executed, for example, stored procedures or SQL text commands </param> // <returns> return the query result set </returns> Public datatable executedatatable (string commandtext, commandtype) {return executedatatable (commandtext, commandtype, null) ;}/// <summary> /// execute a query, return the query result /// </Summary> /// <Param name = "commandtext"> SQL statement to be executed </param> /// <Param name = "commandtype "> type of the query statement to be executed, such as stored procedures or SQL text commands </ Param> /// <Param name = "Parameters"> an array of parameters for a PL-SQL statement or stored procedure </param> /// <returns> </returns> Public datatable executedatatable (string commandtext, commandtype, Params oracleparameter [] parameters) {datatable DATA = new datatable (); // instantiate the datatable, used to load the query result set using (oracleconnection connection = new oracleconnection (connectionstring )) {using (oraclecommand command = new oraclecommand (commandt EXT, connection) {command. commandtype = commandtype; // set the commandtype of command to the specified commandtype. // if both parameters are input, add these parameters if (parameters! = NULL) {foreach (oracleparameter parameter in parameters) {command. parameters. add (parameter) ;}}// instantiate sqldataadapter oracledataadapter adapter = new oracledataadapter (command); adapter by using the sqlcommand instance that contains the query SQL. fill (data); // fill in datatable} return data;} # endregion executedatatable # region executereader // <summary> // send commandtext to connection and generate an oracledatareader. /// </Summary> /// <Param name = "commandtext"> SQL text query command to be executed </param> /// <returns> </returns> Public oracledatareader executereader (string commandtext) {return executereader (commandtext, commandtype. text, null) ;}/// <summary> /// send commandtext to connection and generate an oracledatareader. /// </Summary> /// <Param name = "commandtext"> SQL statement to be executed </param> /// <Param name = "commandtype"> the type of the query statement, for example, stored procedures or SQL text commands </param> /// <returns> </returns> Public oracledatareader executereader (string commandtext, commandtype) {return executereader (commandtext, commandtype, null);} // <summary> // send commandtext to connection and generate an oracledatareader. /// </Summary> /// <Param name = "commandtext"> SQL statement to be executed </param> /// <Param name = "commandtype"> the type of the query statement, for example, stored procedures or SQL text commands </param> /// <Param name = "Parameters"> parameter arrays of transact-SQL statements or stored procedures </param> /// <returns> </returns> Public oracledatareader executereader (string commandtext, commandtype, oraclecommand [] parameters) {oracleconnection connection = new oracleconnection (connectionstring); or Aclecommand command = new oraclecommand (commandtext, connection); // if both parameters are input, add these parameters if (parameters! = NULL) {foreach (oraclecommand parameter in parameters) {command. parameters. add (parameter) ;}} connection. open (); // commandbehavior. the closeconnection parameter indicates that the return command of the connection object associated with the reader object is closed when the reader object is closed. executereader (commandbehavior. closeconnection) ;}# endregion executereader # region executescalar /// <summary> // retrieve a single value (for example, an aggregate value) from the database ). /// </Summary> /// <Param name = "commandtext"> the query PL-SQL text command to be executed </param> /// <returns> </returns> Public object executescalar (string commandtext) {return executescalar (commandtext, commandtype. text, null) ;}//< summary> /// retrieve a single value from the database (for example, an aggregate value ). /// </Summary> /// <Param name = "commandtext"> SQL statement to be executed </param> /// <Param name = "commandtype"> the type of the query statement, such as stored procedures or PL-SQL text commands </param> /// <returns> </returns> Public object executescalar (string commandtext, commandtype) {return executescalar (commandtext, commandtype, null);} // <summary> // retrieve a single value from the database (for example, an aggregate value ). /// </Summary> /// <Param name = "commandtext"> SQL statement to be executed </param> /// <Param name = "commandtype"> the type of the query statement, such as stored procedures or SQL text commands </param> /// <Param name = "Parameters"> an array of parameters for a PL-SQL statement or stored procedure </param> /// <returns> </returns> Public object executescalar (string commandtext, commandtype, oracleparameter [] parameters) {object result = NULL; using (oracleconnection connection = new oracleconnection (connec Tionstring) {using (oraclecommand command = new oraclecommand (commandtext, connection) {command. commandtype = commandtype; // set the commandtype of command to the specified commandtype. // If parameters are input at the same time, add these parameters if (parameters! = NULL) {foreach (oracleparameter parameter in parameters) {command. parameters. add (parameter) ;}} connection. open (); // open the database connection result = command. executescalar () ;}} return result; // return the first column of the first row of the query result, ignore other rows and columns} # endregion executescalar # region executenonquery // <summary> // add, delete, and modify a database /// </Summary> /// <Param name = "commandtext"> query pl-SQL text commands to be executed </param> // <returns> </returns> Public int executenon Query (string commandtext) {return executenonquery (commandtext, commandtype. text, null );} /// <summary> /// add, delete, modify, and delete a database /// </Summary> /// <Param name = "commandtext"> pl-SQL statement to be executed </param> /// <Param name = "commandtype"> type of the query statement to be executed, for example, stored procedures or pl-SQL text commands </param> // <returns> </returns> Public int executenonquery (string commandtext, commandtype) {return executenonquery (commandtext, commandtype, Null );} /// <summary> /// add, delete, modify, and delete a database /// </Summary> /// <Param name = "commandtext"> pl-SQL statement to be executed </param> /// <Param name = "commandtype"> type of the query statement to be executed, for example, stored procedures or pl-SQL text commands </param> // <Param name = "Parameters"> pl-SQL statements or parameter arrays of stored procedures </param> // /<returns> return the number of rows affected by the execution </returns> Public int executenonquery (string commandtext, commandtype, oracleparameter [] parameters) {int COUNT = 0; using (Oracle Connection connection = new oracleconnection (connectionstring) {using (oraclecommand command = new oraclecommand (commandtext, connection) {command. commandtype = commandtype; // set the commandtype of command to the specified commandtype. // If parameters are input at the same time, add these parameters if (parameters! = NULL) {foreach (oracleparameter parameter in parameters) {command. parameters. add (parameter) ;}} connection. open (); // open the database connection count = command. executenonquery () ;}} return count; // return the number of affected rows in the database after the add, delete, and modify operation is executed.} # endregion executenonquery}
The call code in the CS code is as follows:
OraDbHelper dbHelper = new OraDbHelper(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString.ToString()); string sql = "insert into SYIT_POSTINFORM " + " ( ZYXTYPE,GRADENM,TITLE,FBRNM,FBTM,YXTM,CONTS,FROMSR) values "; sql += "( '" + sclass + "'"; sql += ", '" + gwxx[1] + "'"; sql += ", '" + gwxx[0] + "'"; sql += ",' " + gwxx[2] + "'"; sql += ", to_date('" + gwxx[3] + "','yyyy/MM/DD')"; sql += ", to_date('" + gwxx[5] + "','yyyy/MM/DD')"; sql += ", :lgContent "; sql += ", '" + gwxx[4] + "'"; sql += " )"; OracleParameter[] parameters = { new OracleParameter("lgContent",OracleType.Clob) }; parameters[0].Value = gwxx[6]; dbHelper.ExecuteNonQuery(sql, CommandType.Text, parameters);