I am trying to make a filter system for a gridview and I have a DDL that gets column names from my database, and a text box that the user enters values into. You then click add to put it in the list box in a where clause format.
Attachment 96247
The problem I am having, is if I have 2 states I want to filter by, it adds "State = 'FL' AND State = 'CA'", which we know does not work because it can't equal both. I need to find a way to justify if the State column has already been used in the where clause/listbox.
Here is code:
I don't think the sub Search() will be of any interest to this issue, but I put it there just incase.
Attachment 96247
The problem I am having, is if I have 2 states I want to filter by, it adds "State = 'FL' AND State = 'CA'", which we know does not work because it can't equal both. I need to find a way to justify if the State column has already been used in the where clause/listbox.
Here is code:
vb .net Code:
'Adding the filters to DDL Protected Sub btnAddFilter_Click(sender As Object, e As System.EventArgs) Handles btnAddFilter.Click lbFilters.Items.Add(ddlSearch.Text & " = '" & txtFor.Text & "'") End Sub 'Building them to where clause Public Function buildSearch() As String For i = 0 To lbFilters.Items.Count - 1 filterString = filterString + lbFilters.Items(i).ToString + " AND " Next Return filterString End Function 'Creating query string and filtering Public Sub Search() Dim searchString As String = "SELECT Control_Number, Status, OrderNumber, State, County, Address, Date_Received, Priority, Client_Name From orders, client WHERE " Dim listString As String = "SELECT Control_Number From orders WHERE " searchString = searchString + buildSearch() listString = listString + buildSearch() Session("SelectCommand") = searchString & "orders.Client = client.ClientID ORDER BY Control_Number" SqlDataSourceDelete.SelectCommand = Session("SelectCommand") Session("OrderList") = Left(listString, listString.Length - 5) End Sub
I don't think the sub Search() will be of any interest to this issue, but I put it there just incase.