Hi all,
I have already written a code to search for staff records from my staff database and it's working fine, but the problem is, if someone enters a wrong a wrong staff id or just any number or alphabets, it still displays the "Found Record" message, instead of "No Record Found".
Please I need to write a check if a valid staff id is entered in the search textbox and if its invalid, "No Record Found" should be displayed.
Here's my code below. Thanks for your help in advance
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
provSrcStaf = "PROVIDER=Microsoft.ACE.Oledb.12.0;"
souSrcStaf = "DATA SOURCE=D:\RTLSALimited.accdb"
conSrcStaf.ConnectionString = provSrcStaf & souSrcStaf
If txtSearch.Text = "" Then
MessageBox.Show("Enter valid Staff ID", "RTL SA Rubber Limited.", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtSearch.Focus()
Else
StafSQL = "SELECT * FROM Staff WHERE Staff_ID='" & txtSearch.Text & "'"
daSrcStaf = New OleDb.OleDbDataAdapter(StafSQL, conSrcStaf)
daSrcStaf.Fill(dsSrcStaf, "Staff2")
inc = 0
MessageBox.Show("Record found!", "RTL SA Rubber Limited.", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtStaffName.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(1)
txtDesignation.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(2)
txtAddress.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(3)
txtTelNo.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(4)
txtUsername.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(5)
txtPassword.Text = dsSrcStaf.Tables("Staff2").Rows(inc).Item(6)
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSearch.Enabled = False
End If
End Sub