WaAh!
My form was working fine earlier but later it displays Invalid Operation Exception was unhandled. I don't know what's wrong with my form every time I load it.I checked its codes but I find what's wrong with it.
If I'm going to remove Transaction.Cou rses.Show(False , txtSearch.Text) at line #2 of frmCourses it works fine. Of course I cannot filter the records : (
This is my sample codes
clsCourses
[CODE=vbnet]
#Region " Variable Declarations... "
Private ModColor As Boolean
Private SQLString As String
Private i As Integer
Private adItem As ListViewItem
Private rsCourses As OleDbDataReader
Private cmdCourses As New OleDbCommand
#End Region
Public Sub Show(ByVal ShowAllList As Boolean, Optional ByVal Search As String = vbNullString)
Windows.Forms.C ursor.Current = Cursors.WaitCur sor
If ShowAllList Then
SQLString = "Select * From Courses Order By Title ASC"
Else
SQLString = "Select * From Courses Where CourseID Like '%" & Search & _
"%' Or Title Like '%" & Search & "%' Or Description Like '%" & _
Search & "%' Order By Title ASC"
End If
Call SetConnection()
cmdCourses = New OleDbCommand(SQ LString, dbConnection)
cmdCourses.Comm andType = CommandType.Tex t
rsCourses = cmdCourses.Exec uteReader
frmCourses.lvwC ourses.Items.Cl ear()
While rsCourses.Read
adItem = frmCourses.lvwC ourses.Items.Ad d(rsCourses(0), 0) 'Course ID
adItem.SubItems .Add(rsCourses( 1)) 'Title
adItem.SubItems .Add(rsCourses( 2)) 'Description
End While
frmCourses.lblT otalRecords.Tex t = "Total Records: " & frmCourses.lvwC ourses.Items.Co unt
If frmCourses.lvwC ourses.Items.Co unt > 0 Then
frmCourses.lblS howStatus.Visib le = False
Else
frmCourses.lblS howStatus.Visib le = True
End If
For i = 0 To frmCourses.lvwC ourses.Items.Co unt - 1
If ModColor = True Then
frmCourses.lvwC ourses.Items(i) .BackColor = Color.AliceBlue
ModColor = False
Else
frmCourses.lvwC ourses.Items(i) .BackColor = Color.White
ModColor = True
End If
Next
rsCourses.Close ()
Call CloseConnection ()
Windows.Forms.C ursor.Current = Cursors.Default
End Sub[/CODE]
frmCourses
[CODE=vbnet]Private Sub txtSearch_TextC hanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles txtSearch.TextC hanged
Transaction.Cou rses.Show(False , txtSearch.Text)
End Sub
Private Sub frmCourses_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Main.SetChildFo rm(frmMain, Me)
Transaction.Cou rses.Show(True)
End Sub
[/CODE]
Rey Sean
My form was working fine earlier but later it displays Invalid Operation Exception was unhandled. I don't know what's wrong with my form every time I load it.I checked its codes but I find what's wrong with it.
If I'm going to remove Transaction.Cou rses.Show(False , txtSearch.Text) at line #2 of frmCourses it works fine. Of course I cannot filter the records : (
This is my sample codes
clsCourses
[CODE=vbnet]
#Region " Variable Declarations... "
Private ModColor As Boolean
Private SQLString As String
Private i As Integer
Private adItem As ListViewItem
Private rsCourses As OleDbDataReader
Private cmdCourses As New OleDbCommand
#End Region
Public Sub Show(ByVal ShowAllList As Boolean, Optional ByVal Search As String = vbNullString)
Windows.Forms.C ursor.Current = Cursors.WaitCur sor
If ShowAllList Then
SQLString = "Select * From Courses Order By Title ASC"
Else
SQLString = "Select * From Courses Where CourseID Like '%" & Search & _
"%' Or Title Like '%" & Search & "%' Or Description Like '%" & _
Search & "%' Order By Title ASC"
End If
Call SetConnection()
cmdCourses = New OleDbCommand(SQ LString, dbConnection)
cmdCourses.Comm andType = CommandType.Tex t
rsCourses = cmdCourses.Exec uteReader
frmCourses.lvwC ourses.Items.Cl ear()
While rsCourses.Read
adItem = frmCourses.lvwC ourses.Items.Ad d(rsCourses(0), 0) 'Course ID
adItem.SubItems .Add(rsCourses( 1)) 'Title
adItem.SubItems .Add(rsCourses( 2)) 'Description
End While
frmCourses.lblT otalRecords.Tex t = "Total Records: " & frmCourses.lvwC ourses.Items.Co unt
If frmCourses.lvwC ourses.Items.Co unt > 0 Then
frmCourses.lblS howStatus.Visib le = False
Else
frmCourses.lblS howStatus.Visib le = True
End If
For i = 0 To frmCourses.lvwC ourses.Items.Co unt - 1
If ModColor = True Then
frmCourses.lvwC ourses.Items(i) .BackColor = Color.AliceBlue
ModColor = False
Else
frmCourses.lvwC ourses.Items(i) .BackColor = Color.White
ModColor = True
End If
Next
rsCourses.Close ()
Call CloseConnection ()
Windows.Forms.C ursor.Current = Cursors.Default
End Sub[/CODE]
frmCourses
[CODE=vbnet]Private Sub txtSearch_TextC hanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles txtSearch.TextC hanged
Transaction.Cou rses.Show(False , txtSearch.Text)
End Sub
Private Sub frmCourses_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Main.SetChildFo rm(frmMain, Me)
Transaction.Cou rses.Show(True)
End Sub
[/CODE]
Rey Sean
Comment