public void UpdateMyData(DataSet ds) { // The same applies for the Update. It's not necessary to Open/Close the connection. SqlDataAdapter da = new SqlDataAdapter("select * from bob", this.oConnection); SqlCommandBuilder sb = new SqlCommandBuilder(da); da.Update(ds); }Or you can create the various update commands yourself instead of using the CommandBuilder:
public void UpdateMyData(DataSet ds) { SqlCommand sc = new SqlCommand(); sc.Connection = this.oConnection; da = new SqlDataAdapter(sc); da.InsertCommand = new SqlCommand("Insert into bob (xyz, abc) VALUES ( @xyz, @abc )", sc.Connection); da.InsertCommand.Parameters.Add("@xyz", SqlDbType.Int, 8, "xyz"); da.InsertCommand.Parameters.Add("@abc", SqlDbType.VarChar, 50, "abc"); // do the same for da.DeleteCommand & da.UpdateCommand da.Update(ds); }Or, you can take total control, not use the da.Update() and do it all yourself (this is basically the same code that gets done behind the scenes by the da.Update() method:
public void UpdateMyData(DataSet ds) { SqlCommand sc = new SqlCommand(); sc.Connection = this.oConnection; sc.Connection.Open(); foreach (DataRow Row in ds.Tables[0].Rows) { switch (Row.RowState) { case DataRowState.Added : sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )"; sc.Parameters.Clear(); sc.Parameters.Add("@xyz", Row["xyz"]); sc.Parameters.Add("@abc", Row["abc"]); sc.ExecuteNonQuery(); break; // Do the same for DataRowState Deleted and Modified case DataRowState.Deleted : break; case DataRowState.Modified : break; } } sc.Connection.Close(); }~~Bonnie