I was just thinking, there is another way to do this (but i'm not saying this is the best coding and db practice as per the books) but here you go:
private function MakeSQLStatement() as string
dim sqlString as String
dim sqlLike as String = ""
'put here the beginning of the query until the like clause.
sqlString = "SELECT...."
'now build the query as you should go futher
if (txtStatus.Text.ToString() <> "") then
if (sqlLike = "") then
sqlLike = " LIKE (Status = '" & txtStatus.Text.ToString() & "'"
else
sqlLike = sqlLike & " (Status = '" & txtStatus.Text.ToString() & "'"
end if
end if
if (txtOffice.Text.ToString() <> "") then
if (sqlLike="") then
sqlLike = " LIKE (Office = '" & txtOffice.Text.Tostring() & "'"
else
sqlLike = sqlLike & " (Office = '" & txtOffice.Text.ToString() & "'"
end if
end if
'Do same here for Each text boxes with data to search on
'Return value
MakeSQLStatement = sqlString & sqlLike
end function
OK, just check the
VB syntax -> i'm used to the C# but it should be ok.
Do you understand this function?
Helga