在删除一类的时候,删除了指定一类还有它下面的一类
而用sql查询分析器执行:exec hzpDeleteclass 16 只删除一类,帮我看看是不是下面的代码有问题
public void MyDataGrid_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection myConnection = new SqlConnection("server=(local);UID=sa;PWD=;database=News");
SqlDataAdapter myCommand = new SqlDataAdapter("hzpDeleteClass", myConnection); myCommand.SelectCommand.CommandType = CommandType.StoredProcedure; myCommand.SelectCommand.Parameters.Add(new SqlParameter("@classID", SqlDbType.Int));
myCommand.SelectCommand.Parameters["@classID"].Value = MyDataGrid.DataKeys[(int)e.Item.ItemIndex]; DataSet ds = new DataSet();
myCommand.Fill(ds, "hzpclass"); MyDataGrid.DataSource=ds.Tables["hzpclass"].DefaultView;
MyDataGrid.DataBind(); }

解决方案 »

  1.   

    SqlConnection myConnection = new SqlConnection("server=(local);UID=sa;PWD=;database=News");
    SqlDataAdapter myCommand = new SqlDataAdapter("hzpDeleteClass", myConnection); myCommand.DeleteCommand.CommandType = CommandType.StoredProcedure; myCommand.DeleteCommand.Parameters.Add(new SqlParameter("@classID", SqlDbType.Int));
    myCommand.DeleteCommand.Parameters["@classID"].Value = MyDataGrid.DataKeys[(int)e.Item.ItemIndex];                            myCommand.Update(); DataSet ds = new DataSet();
    myCommand.Fill(ds, "hzpclass"); MyDataGrid.DataSource=ds.Tables["hzpclass"].DefaultView;
    MyDataGrid.DataBind();
      

  2.   

    記住一點就可以了SqlDataAdapter 的FILL函數是不會執行DELETECOMMAND,UPDATECOMMAND,INSERTCOMMAND的,它只會執行SELECTCOMMAND
    不管你的存儲過程有什麽命令,能返回一個表就可以了
    按照你的意思,傳一個參數可以刪除這一記錄,並且返回表,這沒什麽問題,你開始的方法是對的