Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP.NET: Index was out of range

    I'm getting "Index was out of range. Must be non-negative and less than the size of the collection." error. Does anybody know what is it?

    I have a sub which filters data from a table and then binds them to a datagrid. Something like -
    'Build SQL string
    da = New OleDbDataAdapter(SQL, ConnString)
    da.Fill(ds) 'ds is a dataset
    Session("View") = ds.Tables(0).DefaultView
    dataGrid.DataSource = Session("View")
    dataGrid.DataBind()

    I can't debug this because it's working fine on my computer in devel. mode.
    It also works when I enter a filter criteria on the server. But it doesn't when there is no criteria entered. Then I get the abovementioned message. I assume this is something related to the postback.

    Any ideas? Thanks

  • #2
    Regular Coder
    Join Date
    Feb 2004
    Location
    Earth
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try
    Session("View") = ds.Tables(0).DefaultView
    catch
    throw new exception (ds.Tables.count.tostring)
    end try

    and you will see if you table collection is empty


  •  

    Posting Permissions

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