Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pass Datatable FROM C# TO Oracle Stored PROCEDURE
- USING SYSTEM;
- USING SYSTEM.Data;
- USING Oracle.DataAccess.Client;
- class OracleDataAdapterSample
- {
- static void Main()
- {
- string constr = "User Id=scott;Password=tiger;Data Source=oracle";
- string cmdstr = "SELECT empno, sal from emp";
- // CREATE the adapter WITH the selectCommand txt AND the
- // connection string
- OracleDataAdapter adapter = NEW OracleDataAdapter(cmdstr, constr);
- // CREATE the builder FOR the adapter TO automatically generate
- // the Command WHEN needed
- OracleCommandBuilder builder = NEW OracleCommandBuilder(adapter);
- // CREATE AND fill the DataSet USING the EMP
- DataSet dataset = NEW DataSet();
- adapter.Fill(dataset, "EMP");
- // Get the EMP TABLE FROM the dataset
- DataTable TABLE = dataset.Tables["EMP"];
- // Indicate DataColumn EMPNO IS UNIQUE
- // This IS required BY the OracleCommandBuilder TO UPDATE the EMP TABLE
- TABLE.Columns["EMPNO"].UNIQUE = TRUE;
- // Get the FIRST ROW FROM the EMP TABLE
- DataRow ROW = TABLE.ROWS[0];
- // UPDATE the salary
- double sal = double.Parse(ROW["SAL"].ToString());
- ROW["SAL"] = sal + .01;
- // Now UPDATE the EMP USING the adapter
- // The OracleCommandBuilder will CREATE the UpdateCommand FOR the
- // adapter TO UPDATE the EMP TABLE
- adapter.UPDATE(dataset, "EMP");
- Console.WriteLine("Row updated successfully");
- }
- }
- OracleCommand cmdOra = NEW OracleCommand(StoredProcedureName, Connection);
- cmdOra.CommandType = CommandType.StoredProcedure;
- OracleDataAdapter da = NEW OracleDataAdapter();
- da.InsertCommand = cmdOra;
- da.UPDATE(dsDataSet);
Add Comment
Please, Sign In to add comment