Hmm i found out there is a bug in the code...it works well on the first time of execution however when i add a clear button to clear all the values and rerun the search button it fails to work
my codes are:
Dim search1 As String = Me.CBsymp1.Text
Dim search2 As String = Me.CBsymp2.Text
Dim search3 As String = Me.CBsymp3.Text
Dim search4 As String = Me.CBsymp4.Text
Dim search5 As String = Me.CBsymp5.Text
Dim strSQL As String
Dim First As Boolean = True ' First keeps track of which to use - WHERE.. or AND...
strSQL = "SELECT GeneralSymptoms1, GeneralSymptoms2, GeneralSymptoms3, GeneralSymptoms4, GeneralSymptoms5, PainType, AreaOfEffect, DurationPerDay, PainOccurance, TypeofSickness FROM Symptoms "
If Not CBsymp1.SelectedIndex = -1 Then
strSQL += "Where GeneralSymptoms1='" & search1 & "'"
First = False
End If
If Not CBsymp2.SelectedIndex = -1 Then
If First Then
strSQL += " WHERE"
First = False
Else
strSQL += " AND"
End If
strSQL += " GeneralSymptoms2='" & search2 & "'"
End If
If Not CBsymp3.SelectedIndex = -1 Then
If First Then
strSQL += " WHERE"
First = False
Else
strSQL += " AND"
End If
strSQL += " GeneralSymptoms3='" & search3 & "'"
End If
If Not CBsymp4.SelectedIndex = -1 Then
If First Then
strSQL += " WHERE"
First = False
Else
strSQL += " AND"
End If
strSQL += " GeneralSymptoms4='" & search3 & "'"
End If
If Not CBsymp5.SelectedIndex = -1 Then
If First Then
strSQL += " WHERE"
First = False
Else
strSQL += " AND"
End If
strSQL += " GeneralSymptoms5='" & search3 & "'"
End If
Dim cmd As OleDbCommand = New OleDbCommand(strSQL, cnn)
Try
cnn.Open()
Dim reader As OleDbDataReader = cmd.ExecuteReader
If reader.Read() Then
Me.CBsymp1.Text = reader.GetString(0)
Me.CBsymp2.Text = reader.GetString(1)
Me.CBsymp3.Text = reader.GetString(2)
Me.CBsymp4.Text = reader.GetString(3)
Me.CBsymp5.Text = reader.GetString(4)
Me.TextBox1.Text = reader.GetString(5)
Me.TextBox2.Text = reader.GetString(6)
Me.TextBox3.Text = reader.GetString(7)
Me.TextBox4.Text = reader.GetString(8)
Me.TextBox5.Text = reader.GetString(9)
Me.GBResults.Visible = True
MsgBox("Sickness Found")
Else
Me.CBsymp1.ResetText()
Me.CBsymp2.ResetText()
Me.CBsymp3.ResetText()
Me.CBsymp4.ResetText()
Me.CBsymp5.ResetText()
Me.TextBox1.ResetText()
Me.TextBox2.ResetText()
Me.TextBox3.ResetText()
Me.TextBox4.ResetText()
Me.TextBox5.ResetText()
MsgBox("Please enter more fields!")
End If
reader.Close()
Finally
Try
cnn.Close()
Catch : End Try
End Try
cnn.Close()