Guest User

Untitled

a guest
Sep 3rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Pass Datatable FROM C# TO Oracle Stored PROCEDURE
  2. USING SYSTEM;
  3. USING SYSTEM.Data;
  4. USING Oracle.DataAccess.Client;
  5.  
  6. class OracleDataAdapterSample
  7. {
  8.   static void Main()
  9.   {
  10.     string constr = "User Id=scott;Password=tiger;Data Source=oracle";
  11.     string cmdstr = "SELECT empno, sal from emp";
  12.  
  13.     // CREATE the adapter WITH the selectCommand txt AND the
  14.     // connection string
  15.     OracleDataAdapter adapter = NEW OracleDataAdapter(cmdstr, constr);
  16.  
  17.     // CREATE the builder FOR the adapter TO automatically generate
  18.     // the Command WHEN needed
  19.     OracleCommandBuilder builder = NEW OracleCommandBuilder(adapter);
  20.  
  21.     // CREATE AND fill the DataSet USING the EMP
  22.     DataSet dataset = NEW DataSet();
  23.     adapter.Fill(dataset, "EMP");
  24.  
  25.     // Get the EMP TABLE FROM the dataset
  26.     DataTable TABLE = dataset.Tables["EMP"];
  27.  
  28.     // Indicate DataColumn EMPNO IS UNIQUE
  29.     // This IS required BY the OracleCommandBuilder TO UPDATE the EMP TABLE
  30.     TABLE.Columns["EMPNO"].UNIQUE = TRUE;
  31.  
  32.     // Get the FIRST ROW FROM the EMP TABLE
  33.     DataRow ROW = TABLE.ROWS[0];
  34.  
  35.     // UPDATE the salary
  36.     double sal = double.Parse(ROW["SAL"].ToString());
  37.     ROW["SAL"] = sal + .01;
  38.  
  39.     // Now UPDATE the EMP USING the adapter
  40.     // The OracleCommandBuilder will CREATE the UpdateCommand FOR the
  41.     // adapter TO UPDATE the EMP TABLE
  42.     adapter.UPDATE(dataset, "EMP");
  43.  
  44.     Console.WriteLine("Row updated successfully");
  45.   }
  46. }
  47.    
  48. OracleCommand cmdOra = NEW OracleCommand(StoredProcedureName, Connection);
  49. cmdOra.CommandType = CommandType.StoredProcedure;
  50. OracleDataAdapter da = NEW OracleDataAdapter();
  51.  
  52. da.InsertCommand = cmdOra;
  53. da.UPDATE(dsDataSet);
Add Comment
Please, Sign In to add comment