Good evening everyone and hope you all had a good weekend. I am working on a site which allows the user to search database records based on entering either a reference number of a person' last name and then clicking the submit button. This brings the user to a results page which uses the gridview data control in asp.net. I can get each search criteria to work by itself (only include one textbox on the search page) and produce the correct results, and I can get them both to work together (user inputs reference number and last name) using "AND" in my where statement and produce the correct results. However, I need for the customer to have the option to enter either a last name OR a reference ID number and to be able to have my results page produce the correct results. I don't want the user to need to enter information in both the ID and Last Name field, but only one or the other. I have tried to accomplish this by changing AND to OR in my WHERE clause, but the search results will not produce any results with OR in my WHERE clause.
Here is applicable code on my results page:
SelectCommand="SELECT [ID], [F_Name], [L_Name], [Address], [City], [State], [Zip] FROM [Surplus_Funds] WHERE (([ID] = @ID) OR ([L_Name] LIKE '%' + @L_Name + '%'))"> <SelectParameters> <asp:FormParameter FormField="ID" Name="ID" Type="Int32" /> <asp:FormParameter FormField="L_Name" Name="L_Name" Type="String" /> </SelectParameters>
Any tips or help with how to accomplish this task would be appreciated. I need results to be produced based on either or textbox having information input and searched on, but not both textboxes. Thanks in advance and I look forward to talking with someone soon.