SqlDataAdapter.RowUpdated : SqlDataAdapter « System.Data.SqlClient « C# / C Sharp by API






SqlDataAdapter.RowUpdated

 

using System;
using System.Data;
using System.Data.SqlClient;

   class SqlDemo {
      static void Main(){
         string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";

         SqlConnection cn = new SqlConnection(connString);
         try
         {
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Employee", cn);
     
            SqlCommandBuilder cb = new SqlCommandBuilder(da);

            DataSet ds = new DataSet();
            da.Fill(ds, 0, 1, "Employee");

            da.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);
            da.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated);

            DataTable dt = ds.Tables["Employee"];
            dt.Rows[0][1] = "T";

            da.Update(ds, "Employee");

            da.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
            da.RowUpdated -= new SqlRowUpdatedEventHandler(OnRowUpdated);
 
         } catch (SqlException ex) {
            Console.WriteLine(ex.Message);
         }
         finally
         {
            cn.Close();
         }

      }


      static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e) 
      {
         Console.WriteLine("OnRowUpdating event");
         if (e.Status != UpdateStatus.Continue) 
            Console.WriteLine("RowStatus = " + e.Status.ToString());
      } 

      static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e) 
      {
         Console.WriteLine("OnRowUpdating event");
         if (e.Status != UpdateStatus.Continue) 
            Console.WriteLine("RowStatus = " + e.Status.ToString());
      }
  }

      

   
  








Related examples in the same category

1.new SqlDataAdapter
2.SqlDataAdapter.Fill
3.SqlDataAdapter.DeleteCommand
4.SqlDataAdapter.InsertCommand
5.SqlDataAdapter.RowUpdating
6.SqlDataAdapter.SelectCommand
7.SqlDataAdapter.SelectCommand.Parameters.Add
8.SqlDataAdapter.TableMappings
9.SqlDataAdapter.TableMappings.Add
10.SqlDataAdapter.Update
11.SqlDataAdapter.UpdateCommand