Click here to Skip to main content
14,694,375 members
Please Sign up or sign in to vote.
1.00/5 (3 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."


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....
Updated 3-Jul-20 7:02am
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:
if(dt.Rows.Count  > 0 ){
     //Do your stuff here.

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.
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.
yogesh vaidya 27-Jul-17 9:21am
i have a question ,as same

in the end of or stoped my works on end by same problems
Public Class SALES
Private access As New GSTDBCONTROL

Public Function NOTEMPTY(ByVal TEXT As String) As Boolean
Return Not String.IsNullOrEmpty(TEXT)
End Function
Public Function EMPTY(ByVal TEXT As String) As Boolean
Return String.IsNullOrWhiteSpace(TEXT)
End Function
Private Function noerrors(Optional ByVal report As Boolean = False) As Boolean
If Not String.IsNullOrEmpty(access.Exception) Then
If report = True Then MsgBox(access.Exception)
Return False
Return True
End If
End Function
Dim currentrecord As Integer = 0
Dim qt As String = 0
Dim custcode As String = 0
Dim cust_id As String = 0
Dim x_cond As String = 0
' Public textBoxWithPlaceHolder = New Placeholder.PlaceholderTextBox()
Public SL_TYPE As Object = 0
Public CaSHMEMO_NO As String
Public CREDMEMO_NO As String
Public CHALLAN_NO As String
Public prod_type_sl As Single
Public TX_TYPE1 As Object = "0"
Dim prod_sl_code As Single = 0
Dim dmy_freegoods As String
Dim dmy_qty As String
Dim dmy_rt As String

Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXITToolStripMenuItem.Click
MainMenu.GRPmain.Location = New Point(23, 7)
End Sub

Private Sub MENUToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MENUToolStripMenuItem.Click
MainMenu.GRPmain.Location = New Point(23, 7)
End Sub
Private Sub BACKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BACKToolStripMenuItem.Click
GRPSALES1.Visible = True
GRPdeleMENU.Visible = False
lbl_slstype.Visible = False
lbl_invno.Visible = False
lblcust.Visible = False
txt_cust.Visible = False
CMD_CUSTFIND.Visible = False
Label3.Visible = False
Label4.Visible = False
txt_custgst.Visible = False
txt_custpan.Visible = False
GRPSL1.Visible = False
lbl_stat.Visible = False
End Sub
Private Sub SALESToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SALESToolStripMenuItem.Click
GRPSALES1.Visible = False
GRPdeleMENU.Visible = True
End Sub
Private Sub SALES_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
GRPSALES1.Visible = True
GRPSALES1.Size = New Size(322, 44)
GRPSALES1.Location = New Point(12, 9)
lblmyysoft.Text = access.mysoft
dgvsals_tran.Size = New Size(432, 187)
dgvsals_tran.Location = New Point(6, 81)
End Sub
Private Sub S_tran1()
access.Execquery("select * from my_code ")
If NOTEMPTY(access.Exception) Then MsgBox(access.Exception) : Exit Sub
If access.dbdt.Rows.Count < 1 OrElse currentrecord > access.dbdt.Rows.Count - 1 Then Exit Sub
Dim r As DataRow = access.dbdt.Rows(currentrecord)
txt_Sl_tranid.Text = r("id").ToString
txt_Sl_trancode.Text = r("sl_trancode").ToString
txt_SLjv_no.Text = r("jv_no").ToString
CaSHMEMO_NO = r("SL_invoice").ToString
CREDMEMO_NO = r("sl_invoice").ToString
If Not String.IsNullOrEmpty(txt_Sl_tranid.Text) Then txt_Sl_trancode.Text = Val(txt_Sl_trancode.Text) + 1
If Not String.IsNullOrEmpty(txt_Sl_tranid.Text) Then txt_SLjv_no.Text = Val(txt_SLjv_no.Text) + 1
If Not String.IsNullOrEmpty(txt_Sl_tranid.Text) Then CaSHMEMO_NO = Val(CaSHMEMO_NO) + 1
If Not String.IsNullOrEmpty(txt_Sl_tranid.
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..

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