程序如下
Dim serialnum As String = Request.QueryString("serialnum")
        Dim myconnection As SqlConnection        myconnection = New SqlConnection("server=localhost;uid=sa;pwd=02180220;database=zhlgl")        Dim ds As DataSet
        Dim MyCommand As SqlDataAdapter
        MyCommand = New SqlDataAdapter("select dname from jshd where  serialnum='" & serialnum & "'", myconnection)
        ds = New DataSet
        MyCommand.Fill(ds, "jshd")
        Label1.Text = ds.Tables("jshd").Rows(0).Item(0)
        myconnection.Close()
运行后总显示
   在位置 0 处没有任何行。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。
    请问这是什么原因?

解决方案 »

  1.   

    可能是没有返回记录,ds.Tables("jshd")=null了,判断一下。
      

  2.   

    MyCommand.Fill(ds, "jshd")
    '看填充后有值吗?没有值运行下面的就是错误的
    Label1.Text = ds.Tables("jshd").Rows(0).Item(0)=====>
    if (ds.Tables("jshd").Rows(0).Item(0)!=Nothing)
    Label1.Text = ds.Tables("jshd").Rows(0).Item(0)
      

  3.   


    myconnection.Open();没有吧,当然不行了
      

  4.   

    应该是取出的是空记录!你要做判断!
    楼上说得不正确,myconnection可以隐式的自己打开。可以不用自己来打开!