Archive for February, 2009

dataadapter update method

February 21, 2009

//Update the records using update method of dataadapter object

 

   SqlDataAdapter da = new SqlDataAdapter();

            SqlCommand cmd = new SqlCommand();

         

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString() );

            cmd.Connection = con;

            SqlCommand upCmd = new SqlCommand(“update authors set au_lname=@au_lname where au_id=@au_id”, con);

            upCmd.Parameters.Add(“@au_lname”, SqlDbType.VarChar, 40, “au_lname”);

 

            upCmd.Parameters.Add(“@au_id”, SqlDbType.VarChar , 11, “au_id”);

 

            da.UpdateCommand  = upCmd; 

 

 

 

            da.Update(ds);

 

Here parameter values “au_lname” and  “au_id”  are column names in dataset.