0
SqlConnection con = new SqlConnection("Data source=.;Database=training; 
                                       integrated security =true");
DataSet ds = new DataSet();
SqlDataAdapter da;

private void Form1_Load(object sender, EventArgs e)
{
    cmd = new SqlCommand("select *  from mangers",con);
    da = new SqlDataAdapter(cmd );
    da.Fill(ds, "1");
    dataGridView1.DataSource = ds.Tables[0];
}

private void button1_Click(object sender, EventArgs e)
{
    SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
    da.Update(ds, "1");
}

I want to know if I can insert/delete/update in DataGridView then it happen same to database by using stored procedure ? enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • what do you mean by "happen same"? – techspider Sep 07 '16 at 19:22
  • Yes, research SqlDataAdapter on MSDN. There are examples. – Crowcoder Sep 07 '16 at 20:14
  • Do some research on SqlDataAdapter and TableAdapters. I haven't used Tableadapters yet, but I know you can save changes in a DataTable to the database. – Luke Sep 08 '16 at 07:02
  • i mean i want to call method which us stored procedure to insert/ update/delete data in database and send cells of gridview as parameteres so not by using commandbulider and da update dataset .. – Ahmed Ramadan Sep 08 '16 at 07:28
  • You don't have to use CommandBuilder with DataAdapters, in fact, I would recommend they never be used. You can set your own insert, update, delete, select commands that use stored procedures. So go to MSDN and read about it. – Crowcoder Sep 08 '16 at 12:20

0 Answers0