tags:

views:

56

answers:

3

"There is no row at position 0." Hi I keep on getting this error message.

If mytable.Rows.Count >= 0  then
dim  myid = dt.Rows(0).Item(6).ToString
End if

Please help me in this matter and I would never ever like to see this message again.Thanking you all.

qry_Sql = qry_Sql + " select SRNO,EMPNO,ATTN_YR,ATTN_MONTH,"
    qry_Sql = qry_Sql + " GRP,TOT_HRS,MY_ID "
    qry_Sql = qry_Sql + " from ATTD_HRS  "
    qry_Sql = qry_Sql + " ORDER BY EMP_NO "

    If mytable.Rows.Count <= 0 Then
    mygrp = dt.Rows(0).Item(5).ToString ---------------------
    myid = dt.Rows(0).Item(6).ToString 
    End If 
+2  A: 

You should check to see if your table contains any rows...

If mytable.rows.Count > 0 then
    If mytable.rows(0).items(2) >= 0 then
        dim  myid = dt.Rows(0).Item(6).ToString
    End if
End if
Sohnee
I am doing that...sorry I dint mention this before.
ahmed
From your edited post i see "If mytable.Rows.Count <= 0 Then" Thats the wrong way around, you should check if there more than 0 so use '>'
PoweRoy
Thank you that was correct.But while debugging the pointer comes on I and then goes directly to End If.So it means there are more than 0. But I need to store the value in the variable.How can I do that?
ahmed
the amount of rows? dim rowcount = mytable.rows.Count
PoweRoy
I mean i wanted to store the value of the variable(myid,mygrp) from the table.
ahmed
Thank you very much, i got it.
ahmed
+1  A: 

Probably because mytable has no row at position 0, (rows(0) part). You should check if there are rows/items before using them.

PoweRoy
A: 

Please give a bit more information. What type are these variables, and their relation.

Mike
This isn't an answer, and should be a comment.
Michael Shimmins