Bind a textbox with dataset. Perform the Add, Edit and Delete Operation using Binding
Add Parameters for only the Update command. Add in similar way for other type command.

DataView dvDv;
DataSet dstDst;
SqlDataAdapter dad;

SqlConnection conCon = new SqlConnection(“Data Source=.;Initial Catalog=Test;Integrated Security=True”);
dad = new SqlDataAdapter(“Select * from Emp”, conCon);
SqlCommandBuilder cmb = new SqlCommandBuilder(dad);
dstDst = new DataSet();

–For Fiiling The dataset
dad.Fill(dstDst, “Emp”);
dvDv = new DataView();
dvDv.AllowEdit = true;
dvDv.AllowNew = true;
dvDv.AllowDelete = true;
dvDv = dstDst.Tables[“EMP”].DefaultView;

–Bind Control
txtEmpName.DataBindings.Clear();
txtAge.DataBindings.Clear();
txtEmpName.DataBindings.Add(“text”, dvDv, “EmpName”);
txtAge.DataBindings.Add(“text”, dvDv, “empage”);

–For Updating the value in dataset
this.BindingContext[dstDst, “Emp”].EndCurrentEdit();
–Update Dataser
dad.Update(dstDst, “Emp”);

–For Inserting The data
this.BindingContext[dstDst,”Emp”].AddNew
‘Add the value and call the update method
‘ For deleting
this.BindingContext[dstDst,”Emp”].Removeat(0)

–Update Dataser
dad.Update(dstDst, “Emp”);

Advertisements