I have 3 text boxes (txtID, txtName, and txtSurname) in my webform and I populate a repeater based on the values in those text boxes. I need to build a WHERE condition and I want to avoid this:
Surely I can use a better combination of building the WhereCondition string.
Code:
dim WhereCondition as String = ""
if txtID.Text <> "" AND txtName.Text <> "" AND txtSurname.Text <> "" then
WhereCondition = " id = '" & txtID.Text & "' AND name = '" & txtName.Text & "' AND surname = '" & txtSurname.Text & "'"
end if
if txtID.Text <> "" AND txtName.Text = "" AND txtSurname.Text = "" then
WhereCondition = " id = '" & txtID.Text & "'"
end if
if txtID.Text = "" AND txtName.Text <> "" AND txtSurname.Text = "" then
WhereCondition = " name = '" & txtName.Text & "'"
end if
sql = "SELECT * from table WHERE " & WhereCondition