ASP.NET VB throwing a strange error

Discussion in 'ASP.NET / ASP.NET Core' started by jgs3, Jan 5, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello,

    Coding along I wanted to first detect if a field in a datareader record was a certain value then go into a loop to process that and any other records as:

    ' process any full siblings
    try
    if dtr.item("RelType") = 3 then
    DisSib += "<p style='left-margin = 1em'>Full Siblings</p>"
    do while dtr.item("RelType") = 3
    DisSib += _
    "<p style='left-margin = 2em'><a href='critter_details.aspx?id=" &amp; dtr.Item("C.Animal_ID") &amp; "'>" &amp; dtr.Item("Name") &amp; "</a> " &amp; _
    GetReg(1, dtr.Item("Registrations")) &amp; " " &amp; _
    dtr.Item("Color") &amp; " " &amp; _
    dtr.Item("Gender") &amp; " " &amp; _
    dtr.Item("Birthdate").Year &amp; "</P>"
    dtr.Read()
    loop
    end if
    catch e as exception
    ErrorNotification(e, "Error in display sibling routine")
    exit function
    end try

    The error it throws is:

    System.InvalidOperationException: No data exists for the row/column. at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal) at System.Data.OleDb.OleDbDataReader.GetValue(Int32 ordinal) at System.Data.OleDb.OleDbDataReader.get_Item(String name) at DunCity.General.DisSib(Int32 i) in E:\web\duncitycom0\htdocs\critter_details.vb:line 229
    Error number = 5
    Source = System.Data
    Description = No data exists for the row/column.

    Indicating the line in red.

    Has anyboy seen this error and have a suggestion?

    Thanks,
    Jim
     
  2. Hello Joel!


    Thanks for your replies.


    In my code I check for the existance of records and exit if they don't exist before I hit the code shown. My question is, why can I refer to the column value just 2 lines before without the page blowing up on that referance? I would think (here's where I get dangerous) that I can refer to that coloumn as many time as I choose and expect the same results as long as I don't issue a read "dtr.read()". I have never heard of "distructive reads" in an ASP.NET context, but you never know.


    What do you think?


    Jim
     
  3. You need to check to see if the record exists inside the loop. dtr.Read() will return False when there is no record. inside your loop you weren't checking the value returned.


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  4. What is your query? Is it possible after a certain number of records the RelType column doesn't exist?

    It could possibly be complaining about a null value, try this....

    do while (Not IsNothing(dtr("RelType")) AndAlsodtr.item("RelType") = 3)



    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  5. My answer is totally wrong... I just noticed what you are doing. and the reason you are getting that error is because the column does not exist...

    You need to change this...

    dtr.Read()

    To This...

    If (Not dtr.Read()) Then Exit Do


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  6. AH HA! Soit was failing not on the first iteration but on a subsequent trip when I hit EOF. I really appreciate your second set of eye on this issue Joel. Thanks.</o:p>
    </o:p>
    Slightly embarrassed,</o:p>
    Jim</o:p>
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page