954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

There is no row at position 0

Hi again!

I have a database and some tables filled with data.

var club = Baza.Clubs; //Baza is dataset, and Clubs is table
            var schedule = Baza.Schedule; // same as above

            for (int i = 1; i <= 90; i++)
            {
                if(schedule[i].day == 2) // BOOM! Breaks at first pass..
                {
                    //Do something..
                }
            }


When I run my app it throws me this error: There is no row at position 0
and throws me to dataSet.Designer.cs to this part of code:

public ScheduleRow this[int index] {
                get {
                    return ((ScheduleRow)(this.Rows[index]));
                }
            }


Any ideas why this happens?

niggz
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Is Schedule null when it is assigned?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
Is Schedule null when it is assigned?


Sorry, not sure what you mean.. Where is it assigned? At 'var schedule = Baza.schedule'?

And btw, Baza.Clubs has 10 rows according to Locals, but Baza.Schedule does not have any..

niggz
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 
var schedule = Baza.Schedule; // same as above
if(null == schedule)
{
   //Something is wrong before it got to here
}
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
var schedule = Baza.Schedule; // same as above
if(null == schedule)
{
   //Something is wrong before it got to here
}


No, thats okay..

niggz
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Surely there is just a lack of rows in whatever you are pulling as you are looking for the row (2) so the third row in. Run a debug and use a break point to see what is contained within the schedule and see if that helps to solve the issue?

Im making assumptions but the error as Thines01 said could either be that it is null or that the schedule actually contains no rows.

MikeyIsMe
Junior Poster
142 posts since Nov 2010
Reputation Points: 32
Solved Threads: 15
 

Surely there is just a lack of rows in whatever you are pulling as you are looking for the row (2) so the third row in. Run a debug and use a break point to see what is contained within the schedule and see if that helps to solve the issue?

Im making assumptions but the error as Thines01 said could either be that it is null or that the schedule actually contains no rows.


I've been through locals, and it contains only columns, but no rows. I'm not sure why. Why do the other tables work properly?

niggz
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Kind of impossible to tell from the information provided.

Common sense would say either the Baza.Schedule object doesnt contain anything row wise or there is a failing link in your database working somewhere preventing the rows being pulled?

Maybe give us a more extensive code post and an insight into the type of informaation that you should be expecting?

MikeyIsMe
Junior Poster
142 posts since Nov 2010
Reputation Points: 32
Solved Threads: 15
 

I managed to get it to work. The thing I changed was this:

var club = Baza.Clubs; //Baza is dataset, and Clubs is table
    var schedule = Baza.Schedule; // same as above
     
    for (int i = 0; i < schedule.count; i++) // THIS WAS REPLACED
    {
    if(schedule[i].day == 2)
    {
    //Do something..
    }
    }


AND MOST IMPORTANTLY... I added this in form load:

scheduleTableAdapter.Fill(Baza.schedule);


I had some database issues, so I had to delete it, and add again, and thats why this error was created. Thanks guys!

niggz
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: