DataBinding Problem: Index was outside the bounds of the array

Discussion in 'ASP.NET / ASP.NET Core' started by valtersnet0, Jan 5, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Let me preface this with I no very little about basic, im more of a c++ / C# guy myself.

    Assuming you are sure there is a populated table in your dataset

    Well since its a public variable (i assume that scopes it global) why pass it around in the function calls?
    Since the functions would then use the one passedto them instead of the globally scoped one.

    Plusyou also passed the object byval, not by reference.... that would also imply you were working on a copy.


    so:

     
  2. I'm trying to bind a datatable to my datalist and I keep getting this error.
    /emoticons/scool.gif /emoticons/skull.gif
    I've never had this problem before and I've created a simple program to
    make sure it's not the server. The problem I'm having is probably related
    to the fact that I created my dataset as a public variable and then I made
    changes to it in another subroutine. Any advice would be much appreciated.

    Here's some pseudocode
    'public variable
    Dim objdataset as DataSet

    Sub buttonClick( , )
    'open the database
    ' fill the dataset
    ' Send the dataset to DoMore()
    DoMore(objDataSet)
    Try
    DataList1.DataSource=objDataSet.Tables(0)
    DataList1.DataBind
    Catch
    ' Error: Index was outside the bounds of the array
    End Try
    End Sub

    sub DoMore(byVal objDataSet as DataSet)
    ' add rows to the 1st datatable in objDataSet

    End sub
     
  3. Thanks but that wasn't the problem
    It was a good idea to clean up my
    code a bit though. You were right
    all I needed was a global variable.

    Turned out the problem was in my
    function that I call inside my DataList
    I have a function that formats image
    tags for me if I give it the URL of the
    images. The problem was in the code
    for that function. The array was set
    for four elements and I looped to the
    fifth element.

    I wish there was a way to avoid setting
    the dimensions of an array before you
    add elements to it. I can do it but the
    trick I use is to first add all of the elements
    to a string and then Split the string into
    elements of an array. It works but it isn't
    very efficient. Any ideas on how to do it?
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page