问题
public void shanchu(string idd){
string sql = "delete from leave where id=" + idd.ToString();
Class1.ExecuteNonQuery(sql);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string a = GridView1.DataKeys[e.RowIndex].Value.ToString();
dsds.shanchu("a");
}
为什么说我索引超出范围 --------------------编程问答-------------------- 现在啥都看不懂,试试dsds.shanchu("a");改成dsds.shanchu(a); --------------------编程问答--------------------
public void shanchu(string idd)--------------------编程问答-------------------- 二楼三楼说得对,a在GridView1_RowDeleting中是个变量,你把它当字符串用了。 --------------------编程问答-------------------- dsds.shanchu("a");
{
string sql = "delete from leave where id=" + idd.ToString();
Class1.ExecuteNonQuery(sql);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string a = GridView1.DataKeys[e.RowIndex].Value.ToString();
dsds.shanchu(a); // 这里的a不能加双引号
}
==>
dsds.shanchu(a); --------------------编程问答-------------------- a本来就是个字符串 --------------------编程问答-------------------- 我前面参数写的就是字符串类型 怎么可能不加双引号 --------------------编程问答--------------------
你是在调用参数还是给string赋值?没搞清楚这么基础的东西你怎么写代码啊 --------------------编程问答-------------------- a != "a"
前面是变量,后面是一个"a"常量。
你看一下GridView1有无选择吧。如果没选择或者选择有问题就会报索引超出范围。
补充:.NET技术 , C#