In ADO.NET while performing manipulations and crud operations with the SqlDataAdapter you can do it with number of ways.
One way for this purpose is to use command builder class meant.
The load of creating SQL queries can be decreased with the help of CommandBuilder . In other words we can say that, the CommandBuilder helps you to generate update, delete., and insert commands on a single database table for a data adapter.
SqlDataAdapter adapter;
DataSet ds;
DataTable dt;
string connstring = "database=student;server=.;user=sa;password=wintellect";
private void Form1_Load(object sender, EventArgs e)
{
}
private void btndataset_Click(object sender, EventArgs e)
{
// Using DataSet
adapter = new SqlDataAdapter("select * from student_detail", connstring);
ds = new DataSet();
adapter.Fill(ds);// fill the DataSet
dGVshowrecord.DataSource = ds.Tables[0];// Binding DataGridView with DataSet
}
private void btnupdate_Click(object sender, EventArgs e)
{
SqlCommandBuilder cmb = new SqlCommandBuilder(adapter);// Creating instance of SqlCommandBuilder
adapter.Update(ds);// updating changes
}
private void btnclear_Click(object sender, EventArgs e)
{
ds.Clear();// Clear the DataSet
}
}
}
0 Comment(s)