public void MyDataGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string num=e.Item.Cells[1].Text.Trim();
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand1=new SqlCommand("de_news",SqlConnection1);
SqlCommand1.CommandType=CommandType.StoredProcedure;
SqlCommand1.Parameters.Add("@classno",SqlDbType.Char,20);
SqlCommand1.Parameters["@classno"].Value = MyDataGrid.DataKeys[e.Item.ItemIndex];
try
{
SqlConnection1.Open();
int i=SqlCommand1.ExecuteNonQuery();
if(i>0)
{
myLabel.Text="删除成功";
}
}
catch (SqlException e1)
{
myLabel.Text ="数据库操作错误:"+e1.Message;
}
finally
{
SqlConnection1.Close();
}
getClass();
}
为什么按删除时,“classno”对应的值为0或1时可以删除,否则没有反应?
{
string num=e.Item.Cells[1].Text.Trim();
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand1=new SqlCommand("de_news",SqlConnection1);
SqlCommand1.CommandType=CommandType.StoredProcedure;
SqlCommand1.Parameters.Add("@classno",SqlDbType.Char,20);
SqlCommand1.Parameters["@classno"].Value = MyDataGrid.DataKeys[e.Item.ItemIndex];
try
{
SqlConnection1.Open();
int i=SqlCommand1.ExecuteNonQuery();
if(i>0)
{
myLabel.Text="删除成功";
}
}
catch (SqlException e1)
{
myLabel.Text ="数据库操作错误:"+e1.Message;
}
finally
{
SqlConnection1.Close();
}
getClass();
}
为什么按删除时,“classno”对应的值为0或1时可以删除,否则没有反应?
应该只有一个。
你看看de_news储存过程就应该明白了