Error: No data exists for the row/column.

Last post 10-03-2003 4:58 PM by sstoos. 3 replies.

Sort Posts:

  • Error: No data exists for the row/column.

    11-08-2002, 4:59 PM
    • Member
      75 point Member
    • byoung
    • Member since 10-31-2002, 4:52 PM
    • Arizona
    • Posts 15
    I'm converting the free Survey Module from the SQL one into an Access Database version. It's been quite educational, which is mostly what I'm doing it for right now.

    Anyway, I've worked through many error messages, and have come to one I just can't crack myself. I've tried doing some searching on the web but I can't find a solution to my headache. The problem is when I add the Survey Module to a page it doesn't have any default question or anything in the database. Problem is, when the page loads it tries to find out if there are any questions, and when it runs this particular module it errors out complaining the following error message:

    Exception Details: System.InvalidOperationException: No data exists for the row/column.

    Here is what is calling the function, from the .ascx page:
    ----
    Dim RowCount As Integer = 0
    RowCount = SurveyCheck.ExistSurvey(ModuleId)
    If RowCount > 0 Then...
    -----

    Here is the entire function. I do now that if I manually add a Survey Question into the database then this does not occur. So I'm guessing that since there is nothing setup in the database that it is freaking over a null value or some type of thing. I've gone over the SQL method and the Access method a few times and can't seem to find out if I can set a trap to set a default if no records are returned. Help!
    ---
    Public Function ExistSurvey(ByVal ModuleID As Integer) As Integer
    Dim myTools As New Tools()
    Dim myRTConnection As String = myTools.GetConnectionString()

    '<-- Create Instance of Connection and Command Object -->
    Dim myConnection As New OleDbConnection(myRTConnection)
    Dim mySQL As String = "SELECT SurveyID FROM Surveys WHERE (ModuleID = " & ModuleID & ")"

    myConnection.Open()
    Dim myCommand As New OleDbCommand(mySQL, myConnection)
    Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

    myReader.Read()
    Dim MyRowCount As Integer = 0
    MyRowCount = myReader.GetInt32(0)

    myReader.Close()
    myConnection.Close()

    Return CInt(MyRowCount)
    End Function
    ---
    Otherwise, I think most of the rest of the module works fine, but I have only been able to test parts of it so far.

    Brian
    ______________

    B. Young

    www.az-ta.com
  • Re: Error: No data exists for the row/column.

    11-10-2002, 5:12 PM
    • Contributor
      4,805 point Contributor
    • lucast
    • Member since 07-30-2002, 4:32 PM
    • Texas
    • Posts 961
    Brian,

    Just a hunch, but try adding an if before the myreader.read() like this....

    ...
    if myReader.Read then
    Dim MyRowCount As Integer = 0
    MyRowCount = myReader.GetInt32(0)
    end if
    ...

    I've run into problems with null values and datareaders and seem to use this to keep from attempting to read or set a variable when the reader is empty.

    HTH
    Tom Lucas

  • Re: Error: No data exists for the row/column.

    11-11-2002, 8:52 AM
    • Member
      75 point Member
    • byoung
    • Member since 10-31-2002, 4:52 PM
    • Arizona
    • Posts 15
    I can't believe I didn't try that. I've got other code that uses that, and I've seen posts with that as well. Thanks! It seems to have worked on that one!
    ______________

    B. Young

    www.az-ta.com
  • Re: Error: No data exists for the row/column.

    10-03-2003, 4:39 PM
    • Member
      110 point Member
    • sstoos
    • Member since 10-02-2003, 11:40 AM
    • Montana
    • Posts 22
    I was having problems with a similiar situation. This was the fix. Thanks!
Page 1 of 1 (4 items)