asp.net中删除语句
protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse){stringsqlco...
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlconn = "Data Source=.;Initial Catalog=abc;User ID=sa;PassWord=sasa";
SqlConnection conn=new SqlConnection(sqlconn);
string sqlstr = "delete from users where u_ID=@u_ID";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
conn.Open();
try
{
cmd.Parameters.Add("@u_ID", SqlDbType.Int,4);
cmd.Parameters["@u_ID"].Value = GridView1.DataKeys[0].Values;
Label1.Text = "删除成功";
}
catch(SqlException ex)
{
Label1.Text = "删除失败"+ex.Message;
}
conn.Close();
BindGrid();
}
索引超出范围。必须为非负值并小于集合大小。
u_ID是主键 展开
{
string sqlconn = "Data Source=.;Initial Catalog=abc;User ID=sa;PassWord=sasa";
SqlConnection conn=new SqlConnection(sqlconn);
string sqlstr = "delete from users where u_ID=@u_ID";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
conn.Open();
try
{
cmd.Parameters.Add("@u_ID", SqlDbType.Int,4);
cmd.Parameters["@u_ID"].Value = GridView1.DataKeys[0].Values;
Label1.Text = "删除成功";
}
catch(SqlException ex)
{
Label1.Text = "删除失败"+ex.Message;
}
conn.Close();
BindGrid();
}
索引超出范围。必须为非负值并小于集合大小。
u_ID是主键 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询