Insert Data using SqlCommandBuilder : SqlCommandBuilder : ADO.Net C# Examples


C# Examples » ADO.Net » SqlCommandBuilder »

 

Insert Data using SqlCommandBuilder









    
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  ID,  FirstName,  LastName  FROM  Employee",  MyConnection);
        SqlCommandBuilder  MyCmd  =  new  SqlCommandBuilder(MyDataAdapter);
        DataSet  MyDataSet  =  new  DataSet();

        MyDataAdapter.Fill(MyDataSet);

        DataRow  MyRow  =  MyDataSet.Tables[0].NewRow();

        MyRow["ID"]  =  200;
        MyRow["FirstName"]  =  "G";
        MyRow["LastName"]  =  "M";
        MyDataSet.Tables[0].Rows.Add(MyRow);
        MyDataAdapter.Update(MyDataSet);
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlCommandBuilder