Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
HI, i am currently working on a project, when i run the program, there is an error. It says this

System.IndexOutOfRangeException was unhandled by user code
Message="There is no row at position 0."
Source="System.Data"

StackTrace:

at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
at System.Data.RBTree`1.get_Item(Int32 index)
at System.Data.DataRowCollection.get_Item(Int32 index)

...



Please help....its urgent....
Posted
Updated 7-Jul-22 3:27am
Comments
Raje_ 7-Aug-12 1:55am    
Can you post some codes?

If I am not wrong, you are trying to read or loop through the rows from datatable. This error states that the datasource(DataTable) is not having any rows. To avoid this exception use this before you read or loop through datatable:
C#
if(dt.Rows.Count  > 0 ){
     //Do your stuff here.
}



--Amit
 
Share this answer
 
Comments
Kailash_Singh 7-Aug-12 2:58am    
thnx ..........
_Amy 7-Aug-12 3:04am    
Welcome. :)
sommr0 24-Jul-17 3:59am    
it remove error but not woeking
It means that no results were returned from your query. You always have to code defensively and check to see if the Rows array has any items in it before trying to index into it.
 
Share this answer
 
IndexOutOfRange exception is thrown when you attempt to access (Read/ Write) an element of an array with an index which is outside the bounds of the array

As per your problem, I guess you are trying to read or write some array elements which are outside of your array boundary.
 
Share this answer
 
v2
Comments
Patrice T 27-Jul-17 9:55am    
Open a new question for your problem.
yogesh vaidya 27-Jul-17 9:22am    
i have a question ,as same

in the end of or stoped my works on end by same problems
Graeme_Grant 27-Jul-17 9:38am    
This question is over 5-year-old. Please start a new question rather than asking in a tombstoned one.
Manoj M.Dhote 18-Nov-20 16:26pm    
Upsendedmindmen never set as sheduledwork as well as he ignored his likes..
you all need to recreat or make changes in database becaz ur table are overwrite.
 
Share this answer
 
Comments
Dave Kreskowiak 7-Jul-22 10:08am    
This question was answered 10 years ago. Your "answer" offers nothing of value to the discussion and does not address the underlying problem that was described.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900