Update database using the SqlDataAdapter : SqlDataAdapter « Database ADO.net « C# / C Sharp






Update database using the SqlDataAdapter


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

class Class1{
  static void Main(string[] args){
         SqlConnection thisConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
         SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT ID, FirstName FROM Employee", thisConnection);

         SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);

         DataSet thisDataSet = new DataSet();

         thisAdapter.Fill(thisDataSet, "Employee");

         Console.WriteLine("name before change: {0}", thisDataSet.Tables["Employee"].Rows[9]["FirstName"]);

         thisDataSet.Tables["Employee"].Rows[1]["FirstName"] = "Inc";

         thisAdapter.Update(thisDataSet, "Employee");

         Console.WriteLine("name after change: {0}", thisDataSet.Tables["Employee"].Rows[9]["FirstName"]);


  }
}

           
       








Related examples in the same category

1.Add data to database using SqlDataAdapter
2.Delete data from database table using SqlDataAdapter