Delete Data using CommandBuilder : SqlCommandBuilder « ADO.Net « C# / CSharp Tutorial






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

  class MainClass 
  {
    static void Main(string[] args)
    {
      SqlConnection MyConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
      SqlDataAdapter MyDataAdapter = new SqlDataAdapter("SELECT * FROM Employee", MyConnection);
      SqlCommandBuilder MyCmd = new SqlCommandBuilder(MyDataAdapter);
      DataSet MyDataSet = new DataSet();

      MyDataAdapter.Fill(MyDataSet);

      DataColumn[] MyKey = new DataColumn[1];

      MyKey[0] = MyDataSet.Tables[0].Columns[0];
      MyDataSet.Tables[0].PrimaryKey = MyKey;

      DataRow FindMyRow = MyDataSet.Tables[0].Rows.Find(1);

      FindMyRow.Delete();
      MyDataAdapter.Update(MyDataSet);
    }
  }








32.23.SqlCommandBuilder
32.23.1.Insert Data using SqlCommandBuilder
32.23.2.Delete Data using CommandBuilder
32.23.3.Show SQL
32.23.4.Show SQL from SqlCommandBuilder