Results 1 to 9 of 9

Thread: [RESOLVED] There is so a row a position 0

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Resolved [RESOLVED] There is so a row a position 0

    My code:
    Code:
        Sub PopulateGrid()
    
            Me.gvDocList.Visible = False
    
            GetDataForGrid(ds)
    
            If ds.Tables.Count = 0 Then Exit Sub
            If ds.Tables(0).Rows.Count = 0 Then Exit Sub
    
            Me.gvDocList.Visible = True
    
            Try
    
                Me.gvDocList.DataSource = ds
    
                Me.gvDocList.DataBind()
    
            Catch ex As Exception
                Response.Write("Exception in PopulateGrid(): " + ex.Message)
            End Try
        End Sub
    The exception I am getting:
    Exception in PopulateGrid(): There is no row at position 0.

    What the debugger says after I get the exception:
    ? ds.Tables(0).Rows(0).Item(0).ToString
    "10304"

    Isn't that a row at position zero??? I must be tired...I should've gotten that free iced coffee at DD today

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: There is so a row a position 0

    at what line you are getting this exception.......what value of ex.tostring

  3. #3
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: There is so a row a position 0

    where is the code for GetDataForGrid(ds)

  4. #4
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: There is so a row a position 0

    Also check to see if your page is running through the code twice... sometimes I get buttons that bug out and do that.. in that case I just delete the button and replace it with another.

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Re: There is so a row a position 0

    Quote Originally Posted by riteshjain1982
    at what line you are getting this exception.......what value of ex.tostring
    I am calling the exception handler when this line executes: Me.gvDocList.DataBind()

  6. #6
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: There is so a row a position 0

    check if you have any itemdatabound event for dgDOCList ?

  7. #7

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Re: There is so a row a position 0

    Quote Originally Posted by Besoup
    where is the code for GetDataForGrid(ds)
    Code:
        Sub GetDataForGrid()
    
            Dim connString As String = _
                ConfigurationManager.ConnectionStrings("ConnectMe").ConnectionString
    
            Dim conn As New SqlConnection(connString)
    
            Dim command As New SqlCommand()
            command.CommandType = CommandType.StoredProcedure
            command.Connection = conn
    
            command.CommandText = "up_DocList"
    
            command.Parameters.Add(New SqlParameter("@cstmr_addr_ik", Data.SqlDbType.Int))
            command.Parameters("@cstmr_addr_ik").Value = sCustomerAddrIk
    
            Dim adapter As New SqlDataAdapter(command)
            Try
                adapter.Fill(ds)
            Catch ex As Exception
                Response.Write("GetDataForGrid Exception " + ex.Message)
                conn.Close()
                Exit Sub
            Finally
                conn.Close()
            End Try
    
        End Sub
    ds is defined global in the class:
    Code:
        Dim ds As New DataSet
    I should tell you that this was working perfectly when I defined the SqlDataSource in my designer and set the gridview property to use it also in the designer. I was just running a simple stored proc that took one parameter. Now I am making it more sophisticated in that I have to build the WHERE clause in the stored procedure according to what I pass in for criteria. So I moved the logic to the code-behind. But before even adding the logic for the WHERE clause, I thought I'd check to make sure it still works as it was. Good thing, since it doesn't...

    And everything seems to be executing just once... no odd behavior noticed.

    Thanks for your help Besoup and riteshjain1982.

  8. #8
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: There is so a row a position 0

    did u checked for ItemDataBound event of dgDOCList ?

  9. #9

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    Re: There is so a row a position 0

    Quote Originally Posted by riteshjain1982
    did u checked for ItemDataBound event of dgDOCList ?
    No, I hadn't checked this. You and I were cross-threading...

    Anyway, it is a gridview not a datagrid but you are absolutely right! In the gridview's RowDataBound event I am doing additional processing to format the last column of my grid. I make another call to the database. I don't have an exception handler here . So my exception was bubbling up and the wrong procedure was getting blamed.

    I should've seen the symptoms of this. On my page, the grid's first row was getting generated except for the last column and then I exceptioned (did I say I was tired yesterday?!)

    Thank you so much!
    Marlene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width