SqlDataAdapter Update Method
Diagram:
Steps:
Example: private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("connetionString"); string qry = "SELECT * FROM SOMETABLE"; SqlDataAdapter da = new SqlDataAdapter(qry,con); //Fill the DataSet DataSet ds = new DataSet(); da.Fill(ds, "SomeTable"); //Update a row in DataSet Table DataTable dt = ds.Tables["SomeTable"]; dt.Rows[0]["SomeColumn"] = "xyz";
string sql = "update sometable set somecolumn = 10 where ..."; SqlDataAdapter adapter = new SqlDataAdapter(); try { connection.Open(); SqlCommand cmd = new SqlCommand(sql, con); //select the update command adapter.UpdateCommand=cmd; //update the data source adapter.Update(ds,"SomeTable"); MessageBox.Show ("DataBase updated !! "); } catch (Exception ex) { connection.Close(); } } Happy Learning...
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: