1. modify data
Copy codeThe Code is as follows:
DataRow dr = hRDataSet. Tables ["emp"]. Rows. Find (textBox3.Text );
// DataRow dr = hRDataSet. Tables ["emp"]. Select ("id =" + textBox3.Text) [0];
Dr. BeginEdit ();
Dr ["name"] = textBox1.Text;
Dr. EndEdit ();
SqlCommandBuilder cmd = new SqlCommandBuilder (empTableAdapter );
EmpTableAdapter. Update (hRDataSet );
This. empTableAdapter. Fill (this. hRDataSet. emp );
2. Insert data
Copy codeThe Code is as follows:
DataSet ds = new DataSet ();
Using (SqlConnection conn = new SqlConnection (ConfigurationManager. ConnectionStrings ["db"]. ConnectionString ))
{
String SQL = "select id, name, age from emp ";
SqlDataAdapter adp = new SqlDataAdapter (SQL, conn );
Adp. Fill (ds );
DataRow dr = ds. Tables [0]. NewRow ();
Dr ["name"] = txtName. Text;
Dr ["age"] = Convert. ToInt32 (txtAge. Text );
SqlCommandBuilder cmd = new SqlCommandBuilder (adp );
Ds. Tables [0]. Rows. Add (dr );
Adp. Update (ds );
}
3. delete data
Copy codeThe Code is as follows:
DataRow dr = hRDataSet. Tables ["emp"]. Rows. Find (textBox3.Text );
// DataRow dr = hRDataSet. Tables ["emp"]. Select ("id =" + textBox3.Text) [0];
Dr. Delete ();
SqlCommandBuilder cmd = new SqlCommandBuilder (empTableAdapter );
EmpTableAdapter. Update (hRDataSet );
This. empTableAdapter. Fill (this. hRDataSet. emp );