InvalidOperationException was unhandled

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #1

    InvalidOperationException was unhandled

    [CODE=vb .net]
    Private Data As OleDbDataReader
    Private Command As New OleDbCommand

    Friend Function Conflict(ByVal DayID As String, ByVal Room As String, ByVal _
    NewTimeStarted As Date, ByVal NewTimeFinished As Date, ByVal SectionUnit As String, _
    ByVal Semester As String) As Boolean
    'Dim SectionUnit As String
    'SectionUnit = Course & " " & Section
    'Conflict = False 'Default Value


    Main.SetConnect ion() 'Set Database Connection

    'PHASE 1 | CHECK ROOM SCHEDULES
    Command = New OleDbCommand("S elect * From LoadSchedules Where Rooms.Title='" & Room & _
    "' And Not Rooms.Title='Fi eld' And Semester='" & Semester & "' And DayID='" _
    & DayID & "'", dbConnection)
    Command.Command Type = CommandType.Tex t
    Data = Command.Execute Reader

    If (Data("TimeStar ted") >= NewTimeStarted) And (Data("TimeStar ted") < NewTimeFinished ) Then
    Conflict = True
    'MsgBox "1 | Conflict sa 1st day. May nakaschedule na sa room na ito."
    ShowConflict(Da ta("SectionUnit "), _
    Data("Rooms.Tit le"), Data("DayID"), _
    Data!TimeStarte d, Data!TimeFinish ed)
    Exit Function
    End If

    Data.Close()
    End Function[/CODE]

    The bold text says "No data exists for the row/column" Please help :'(

    Rey Sean
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    You need to make sure you reader is actually pulling data.

    Sounds like its not which means either your query is not right, or the database doesn't have the data you are expecting it to have.

    Code:
    If Data.Read then
         'your data is there
    else
         'your data is not there
    end if

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Originally posted by jeffstl
      You need to make sure you reader is actually pulling data.

      Sounds like its not which means either your query is not right, or the database doesn't have the data you are expecting it to have.

      Code:
      If Data.Read then
           'your data is there
      else
           'your data is not there
      end if
      You are a little bit right. I've change the query

      [CODE=vb .net][color=#222222]
      1. [font='Courier New',Courier,mo nospace]Private Data As OleDbDataReader[/font]
      2. [font='Courier New',Courier,mo nospace]Private Command As New OleDbCommand[/font]
      3. [font='Courier New',Courier,mo nospace] [/font]
      4. [font='Courier New',Courier,mo nospace]Friend Function Conflict(ByVal DayID As String, ByVal Room As String, ByVal _[/font]
      5. [font='Courier New',Courier,mo nospace] NewTimeStarted As Date, ByVal NewTimeFinished As Date, ByVal SectionUnit As String, _[/font]
      6. [font='Courier New',Courier,mo nospace] ByVal Semester As String) As Boolean[/font]
      7. [font='Courier New',Courier,mo nospace] 'Dim SectionUnit As String[/font]
      8. [font='Courier New',Courier,mo nospace] 'SectionUnit = Course & " " & Section[/font]
      9. [font='Courier New',Courier,mo nospace] 'Conflict = False 'Default Value[/font]
      10. [font='Courier New',Courier,mo nospace] [/font]
      11. [font='Courier New',Courier,mo nospace] [/font]
      12. [font='Courier New',Courier,mo nospace] Main.SetConnect ion() 'Set Database Connection[/font]
      13. [font='Courier New',Courier,mo nospace] 'PHASE 1 | CHECK ROOM SCHEDULES[/font]
      14. [font='Courier New',Courier,mo nospace] Command = New OleDbCommand("S elect * From LoadSchedules Where Rooms.Title='" & Room & _[/font]
      15. [font='Courier New',Courier,mo nospace] "' And Not Rooms.Title='Fi eld' And Semester='" & Semester & "' And DayID='" _[/font]
      16. [font='Courier New',Courier,mo nospace] & DayID & "'", dbConnection)[/font]
      17. [font='Courier New',Courier,mo nospace] Command.Command Type = CommandType.Tex t[/font]
      18. [font='Courier New',Courier,mo nospace] Data = Command.Execute Reader[/font]
      19. [font='Courier New',Courier,mo nospace] [/font]
      20. [font='Courier New',Courier,mo nospace] If Data.Read Then[/font]
      21. [font='Courier New',Courier,mo nospace] Conflict = True[/font]
      22. [font='Courier New',Courier,mo nospace] 'MsgBox "1 | Conflict sa 1st day. May nakaschedule na sa room na ito."[/font]
      23. [font='Courier New',Courier,mo nospace] ShowConflict(Da ta("SectionUnit "), _[/font]
      24. [font='Courier New',Courier,mo nospace] Data("Rooms.Tit le"), Data("DayID"), _[/font]
      25. [font='Courier New',Courier,mo nospace] Data!TimeStarte d, Data!TimeFinish ed)[/font]
      26. [font='Courier New',Courier,mo nospace] Exit Function[/font]
      27. Else
      28. Conflict = False
      29. [font='Courier New',Courier,mo nospace] End If[/font]
      30. [font='Courier New',Courier,mo nospace] [/font]
      31. [font='Courier New',Courier,mo nospace] Data.Close()[/font]
      32. [font='Courier New',Courier,mo nospace]End Function[/font]
      [/color]
      [/CODE]

      Thanks : )

      Rey Sean

      Comment

      Working...