SqlCommandBuilder 的使用


            //删除数据
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=TestDataBase");
            SqlDataAdapter da = new SqlDataAdapter("select * from Test_table", conn);
            SqlCommandBuilder sqlCBuilder = new SqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds);
            ds.Tables[0].Rows[0].Delete();
            da.Update(ds); 

        //增加数据
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=TestDataBase");
            SqlDataAdapter da = new SqlDataAdapter("select * from Test_table", conn);
            SqlCommandBuilder sqlCBuilder = new SqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataRow dr = ds.Tables[0].NewRow();
            dr[0] = "1";
            dr[1] = "aa";
            ds.Tables[0].Rows.Add(dr);
            da.Update(ds);

        //修改数据
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=TestDataBase");
            SqlDataAdapter da = new SqlDataAdapter("select * from Test_table", conn);
            SqlCommandBuilder sqlCBuilder = new SqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataRow dr = ds.Tables[0].Rows[0];
            dr[0] = "1";
            dr[1] = "aa";
            ds.Tables[0].Rows.Add(dr);
            da.Update(ds);

你可能感兴趣的:(SqlCommandBuilder 的使用)