第一种:
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
conn.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "select * from xxb";
com.Connection = conn;
DataSet daset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(com);
adapter.Fill(daset);
DataTable table=daset.Tables[0];
DataRow row = table.Rows[1];
row["Age"] = 999;
adapter.UpdateCommand = com;
adapter.UpdateCommand.CommandText = "insert into xxb(Name) values('xiao3')";
adapter.Update(daset);
conn.Dispose();
第二种:
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
conn.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "select * from xxb";
com.Connection = conn;
DataSet daset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(com);
adapter.Fill(daset);
DataTable table = daset.Tables[0];
DataRow row = table.Rows[0];
row["Age"] = 999;
//table.Rows.Add();
//table.NewRow();
//table.Rows.RemoveAt();
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.Update(daset);