增加可以,但就是删除不行。 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");
        }

解决方案 »

  1.   

    if (ds.Tables["yhdetail"].Rows.Count > 0)
    {
         ds.Tables["yhdetail"].Rows[0].Delete();
                
         sda.Update(ds,"yhdetail");
    }
      

  2.   

    也就是为什么RemoveAt()方法不行,而delete()方法才行。
      

  3.   


    sda.Update是根据RowState(行状态来执行的)
     DataRow 使用 Delete 方法后,RowState 将变为 Deleted,这样才能使dataadapter调用相应的deltecommand命令执行删除你可以结贴了.
      

  4.   

    deltecommand
    -->
    deletecommand刚才回答的少打了一个字母e... -_-!
      

  5.   

    找到原因了:在将 DataSet 或 DataTable 与 DataAdapter 和关系型数据源一起使用时,用 DataRow 的 Delete 方法移除行。Delete 方法只是在 DataSet 或 DataTable 中将行标记为 Deleted,而不会移除它。而 DataAdapter 在遇到标记为 Deleted 的行时,会执行其 DeleteCommand 方法以在数据源中删除该行。然后,就可以用 AcceptChanges 方法永久移除该行。如果使用 Remove 删除该行,则该行将从表中完全移除,但 DataAdapter 不会在数据源中删除该行。