I have the following sql statement:
@Firstname is a textbox on my page - txtFirstname
@Surname is a textbox on my page - txtSurname
I am trying to bind the results to a grid by using the following code:
My datasource reads:
If I enter in information in both textboxes it returns the correct results, however if I enter information in one of the boxes, no records appears. If I run the query when configuring the datasource and input only say the firstname it returns the correct results.
What I am trying to achieve is display all records in the database that match any records whose firstname is like/contains txtFirstname or whose Surname is like/contains txtSurname
Code:
SELECT GuestID, Title, Firstname, Surname, AddressLine1, AddressLine2, AddressLine3, AddressLine4, CityTown, Postcode, Country, PhoneHome, PhoneBusiness, PhoneMobile, EmailAddress, Nationality, Sex, Notes FROM Guests WHERE (Firstname = @Firstname) OR (Surname = @Surname)
@Firstname is a textbox on my page - txtFirstname
@Surname is a textbox on my page - txtSurname
I am trying to bind the results to a grid by using the following code:
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.grdGuestList.DataSourceID = GuestSearchResults.ID
End Sub
My datasource reads:
Code:
<asp:SqlDataSource ID="GuestSearchResults" runat="server"
ConnectionString="<%$ ConnectionStrings:MyHotelConnectionString %>"
SelectCommand="SELECT GuestID, Title, Firstname, Surname, AddressLine1, AddressLine2, AddressLine3, AddressLine4, CityTown, Postcode, Country, PhoneHome, PhoneBusiness, PhoneMobile, EmailAddress, Nationality, Sex, Notes FROM Guests WHERE (Firstname = @Firstname) OR (Surname = @Surname)">
<SelectParameters>
<asp:ControlParameter ControlID="txtFirstName" Name="Firstname"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="txtSurname" Name="Surname"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
If I enter in information in both textboxes it returns the correct results, however if I enter information in one of the boxes, no records appears. If I run the query when configuring the datasource and input only say the firstname it returns the correct results.
What I am trying to achieve is display all records in the database that match any records whose firstname is like/contains txtFirstname or whose Surname is like/contains txtSurname