增加可以,但就是删除不行。 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
string sql = "select * from yhDetail where yhID='" + yhid + "'";
SqlCommand comm = new SqlCommand(sql,conn);
SqlDataAdapter sda = new SqlDataAdapter(comm);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(ds,"yhdetail");
dt = ds.Tables["yhdetail"];
int tmp = dt.Rows.Count;
int tmp2 = ds.Tables["yhdetail"].Rows.Count;
if (ds.Tables["yhdetail"].Rows.Count > 0)
{
ds.Tables["yhdetail"].Rows.RemoveAt(0);
sda.Update(ds,"yhdetail");
}
string sql = "select * from yhDetail where yhID='" + yhid + "'";
SqlCommand comm = new SqlCommand(sql,conn);
SqlDataAdapter sda = new SqlDataAdapter(comm);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(ds,"yhdetail");
dt = ds.Tables["yhdetail"];
int tmp = dt.Rows.Count;
int tmp2 = ds.Tables["yhdetail"].Rows.Count;
if (ds.Tables["yhdetail"].Rows.Count > 0)
{
ds.Tables["yhdetail"].Rows.RemoveAt(0);
sda.Update(ds,"yhdetail");
}
{
ds.Tables["yhdetail"].Rows[0].Delete();
sda.Update(ds,"yhdetail");
}
sda.Update是根据RowState(行状态来执行的)
DataRow 使用 Delete 方法后,RowState 将变为 Deleted,这样才能使dataadapter调用相应的deltecommand命令执行删除你可以结贴了.
-->
deletecommand刚才回答的少打了一个字母e... -_-!