Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datatable row loop problem. 1

Status
Not open for further replies.

Xsi

Programmer
May 29, 2015
121
SE
Hello people

I have made a datatable with certain column names, I put the result from a SQL Query into the data table.

now is my problem

when I loop all items in a certain column I recieve this message:

[highlight #CC0000]There is no row at position 10.[/highlight]


this is my code:


Code:
If HashDatatable1.Rows.Count > 0 Then
            For i As Integer = 0 To HashDatatable1.Rows.Count
                Dim cm As String = HashDatatable1.Rows(i).Item(18)
                MsgBox(cm)
            Next
        End If


Could someone help me?

Thank you in advance.


 
Hi,

If your counter base is 0, then your loop limit ought to be row.count - 1.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Count is the total number of rows, however with a zero-based index you have to remember to stop before that count.

For 10 items, it would be 0, 1, 2, ..., 8, 9.

Code:
If HashDatatable1.Rows.Count > 0 Then
    For i As Integer = 0 To HashDatatable1.Rows.Count - 1
        Dim cm As String = HashDatatable1.Rows(i).Item(18)
        MsgBox(cm)
    Next
End If
 
Thank you work as a charm!! yeah I have forget....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top