Hi, could someone help me with the If statement part this this code, I want to be able to search the dataset or recordset, if this a matching value to load the row to the grid, this part works fine. but when I added the if statement part of the code, I ran into trouble. My goal is to be able to let the user know in a way of msgbox when this is now matching record.
Thanks
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim ds As New DataSet
Dim connectionstring As String
connectionstring = "provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.accdb;"
'your select command could select for example 2 fields
'SELECT fieldName1, fieldName2 FROM tableName
Dim query As String = String.Format("SELECT EmpID,LastName,FirstName FROM EmployeeTbl where LastName = '{0}'", txtLastName.Text)
Dim dataAdapter As New OleDb.OleDbDataAdapter(query, connectionstring)
dataAdapter.Fill(ds, "EmployeeTbl")
If query.value Is Nothing Then
MsgBox("No Matching Recorc found, click next to continue")
Else
DataGridViewCheckEmployee.DataSource = ds.Tables(0)
End If
End Sub
Thanks
Quote:
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim ds As New DataSet
Dim connectionstring As String
connectionstring = "provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amaechi\Documents\Databases\Humanresouces.accdb;"
'your select command could select for example 2 fields
'SELECT fieldName1, fieldName2 FROM tableName
Dim query As String = String.Format("SELECT EmpID,LastName,FirstName FROM EmployeeTbl where LastName = '{0}'", txtLastName.Text)
Dim dataAdapter As New OleDb.OleDbDataAdapter(query, connectionstring)
dataAdapter.Fill(ds, "EmployeeTbl")
If query.value Is Nothing Then
MsgBox("No Matching Recorc found, click next to continue")
Else
DataGridViewCheckEmployee.DataSource = ds.Tables(0)
End If
End Sub