Update database using the SqlDataAdapter : SqlDataAdapter : Database C# Source Code


Custom Search

C# Source Code » Database » SqlDataAdapter »

 

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"]);


  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Database
» SqlDataAdapter