HEllo Everyone:
I am new in VB2005, with no programming experience. I am working on a project whith a search screen where I have multiples combo boxes, text boxes and so far everything is working the way I want it, meaning I can search using any of the combo boxes. The problem I am having is that I don't know how to write an Error Handler. I want to be able that if my criteria doesn't match to display a message "No Record Found". Please help
BK.
Here is copy of the code that I have for my serach screen.
*****************************************************
Private Sub get_searchtable_records() Dim conn As New SqlClient.SqlConnection Dim searchtable_string As String = "" Dim searchtable_string2 As String = ""
'Dim strWhereCondition As String
Dim testsearch_connection As New SqlClient.SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=SupportDesk;server=local")
searchtable_string = "SELECT * FROM CallLog" & trimstring searchtable_string2 = "" & trimstring
'This is to search using the Priority Combo Box If Trim(CmbSrPriority.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE Priorityid = '" & CmbSrPriority.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND Priorityid = '" & CmbSrPriority.Text & "' " End If End If '************************* 'This is to search using the Status Combo Box If Trim(CmbSrStatus.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE Statusid = '" & CmbSrStatus.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND Statusid = '" & CmbSrStatus.Text & "' " End If End If '************************* 'This is to search using the District Combo Box If Trim(CmbSrDistrict.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE DistrictNumberID = '" & CmbSrDistrict.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND DistrictNumberID = '" & CmbSrDistrict.Text & "' " End If End If '************************* 'This is to search using the Application Combo Box If Trim(CmbSrApplication.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE Applicationid = '" & CmbSrApplication.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND Applicationid = '" & CmbSrApplication.Text & "' " End If End If '************************* 'This is to search using the Group Combo Box If Trim(CmbSrGroup.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE Groupid = '" & CmbSrGroup.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND Groupid = '" & CmbSrGroup.Text & "' " End If End If '************************* 'This is to search using the Assignee Combo Box If Trim(CmbSrAssignee.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE Assigneeid = '" & CmbSrAssignee.Text & "' " Else searchtable_string2 = searchtable_string2 & " AND Assigneeid = '" & CmbSrAssignee.Text & "' " End If End If '********************************* 'This is to search using the Call Description Combo Box If Trim(TxtSrCallDescription.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE RichTextBox1 LIKE '%" & TxtSrCallDescription.Text & "%' " Else searchtable_string2 = searchtable_string2 & " AND RichTextBox1 LIKE '%" & TxtSrCallDescription.Text & "%' " End If End If '************************* 'This is to search using the Call Resolution Combo Box If Trim(TxtSrCallResolution.Text) <> "" Then If searchtable_string2 = "" Then searchtable_string2 = " WHERE RichTextBox2 LIKE '%" & TxtSrCallResolution.Text & "%' " Else searchtable_string2 = searchtable_string2 & " AND RichTextBox2 LIKE '%" & TxtSrCallResolution.Text & "%' " End If End If '************************* searchtable_string = searchtable_string & searchtable_string2
searchtable_command = New SqlClient.SqlCommand(searchtable_string, testsearch_connection)
searchtable_dataadapter = New SqlClient.SqlDataAdapter(searchtable_command)
If searchtable_command.Connection.State = ConnectionState.Closed Then
searchtable_command.Connection.Open()
End If
searchtable_table.Clear() 'clear table to not show duplicates after refilling
searchtable_dataadapter.Fill(searchtable_table)
searchtable_command.Connection.Close()
Me.DataGridView1.DataSource = searchtable_table
End Sub