当前位置:编程学习 > C#/ASP.NET >>

问题

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)
  {

  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不能加双引号
  }
--------------------编程问答-------------------- 二楼三楼说得对,a在GridView1_RowDeleting中是个变量,你把它当字符串用了。 --------------------编程问答-------------------- dsds.shanchu("a");
==>
dsds.shanchu(a); --------------------编程问答-------------------- a本来就是个字符串  --------------------编程问答-------------------- 我前面参数写的就是字符串类型 怎么可能不加双引号 --------------------编程问答--------------------
引用 6 楼 aa69659 的回复:
我前面参数写的就是字符串类型 怎么可能不加双引号

你是在调用参数还是给string赋值?没搞清楚这么基础的东西你怎么写代码啊 --------------------编程问答-------------------- a != "a"
前面是变量,后面是一个"a"常量。
你看一下GridView1有无选择吧。如果没选择或者选择有问题就会报索引超出范围。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,