jbtman
Programmer
- Jul 13, 2007
- 30
I have a funciton that I am trying to use to filter a datatable of customer records but it always returns all rows.
Am I doing something wrong? Any help appreciated!!
Am I doing something wrong? Any help appreciated!!
Code:
Public Function CustomerLookup(ByVal strFirstName As String, ByVal strLastName As String) As DataTable
Dim dtTemp As DataTable
Dim dv As DataView
dtTemp = GetAllCustomers()
dv = New DataView(dtTemp)
If strFirstName = vbNullString And strLastName <> vbNullString Then
dtTemp.Select("LastName LIKE '" & strLastName & "%'")
ElseIf strFirstName <> vbNullString And strLastName = vbNullString Then
dv.RowFilter = "FirstName LIKE '" & strFirstName & "%'"
Else
dtTemp.Select("FirstName LIKE '%" & strFirstName & "' AND LastName LIKE '%" & strLastName & "'")
End If
dtTemp = dv.Table.Copy
Return dtTemp
End Function