嘿伙计我已经把所有其他相似的话题都弄清楚了但仍然无法解决这个问题,我真的很新的asp.net,C#和数据库我有一个网格视图"删除&#34 ;在它上面
<asp:GridView ID="GridViewSignUps" runat="server"
OnRowDeleting="GridViewSignUps_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
以及填充它的方法:
private void UpdateGridView()
{
SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = fitness_database");
SqlDataAdapter da = null;
DataSet ds = null;
string sqlsel = "select Activity_Name from Activities inner join Sign_Ups on Activities.Activity_Number = Sign_Ups.Activity_number where Member_number = '" + Session["UserId"] + "'";
try
{
da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sqlsel, conn);
ds = new DataSet();
da.Fill(ds);
GridViewSignUps.DataSource = ds;
GridViewSignUps.DataBind();
}
catch (Exception ex)
{
LabelMessage.Text = ex.Message;
}
finally
{
conn.Close();
}
}
我得到了我需要的用户所需的信息但是当我按下删除时我得到了
对象引用未设置为对象的实例。
这是GridViewSignUps_SelectedIndexChanged():
protected void GridViewSignUps_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(@"data source = .\sqlexpress; integrated security = true; database = fitness_database");
SqlDataAdapter da = new SqlDataAdapter("DeleteSignUp", conn);
da.DeleteCommand.CommandType = CommandType.StoredProcedure;
da.DeleteCommand.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = Session["UserID"].ToString();
conn.Open();
da.DeleteCommand.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
LabelMessage.Text = ex.Message;
}
finally {
UpdateGridView();
}
}
存储过程非常简单:
CREATE PROCEDURE [dbo].[DeleteSignUp]
@ID int
AS
begin
delete from Sign_Ups where @ID = Member_number
end
RETURN
我尝试了几种不同的方法,但我根本不知道这个错误意味着什么......提前谢谢