0

Hi all

I want to select data from a database and display it on a GridView. My problem is it doe not return anything when i use the WHERE clause but when i use SELECT * it works. I am new in ASP.NET, please help.

here is the code i used:
[
qlDataSource datasource = new SqlDataSource();
datasource.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString();
datasource.SelectCommandType = SqlDataSourceCommandType.Text;
datasource.SelectCommand = "SELECT FlightID, FlightNo, @DeparturePlace, @DestinationLoc, DepartTime, ArrivalTime, SinglePrice, ReturnPrice FROM Status WHERE DeparturePlace = @DeparturePlace AND DestinationLoc = @DestinationLoc";
datasource.SelectParameters.Add("DeparturePlace", DropDownList1.SelectedValue);
datasource.SelectParameters.Add("DestinationLoc", DropDownList2.SelectedValue);
qlDataSource datasource = new SqlDataSource();
datasource.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString();
datasource.SelectCommandType = SqlDataSourceCommandType.Text;
datasource.SelectCommand = "SELECT FlightID, FlightNo, @DeparturePlace, @DestinationLoc, DepartTime, ArrivalTime, SinglePrice, ReturnPrice FROM Status WHERE DeparturePlace = @DeparturePlace AND DestinationLoc = @DestinationLoc";
datasource.SelectParameters.Add("DeparturePlace", DropDownList1.SelectedValue);
datasource.SelectParameters.Add("DestinationLoc", DropDownList2.SelectedValue);]

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by w_3rabi
0

I pasted the code twice, ignore the repeat of the first code.

0

What is the column of DeparturePlace?
Number?
What is the value of DropDownList1.SelectedValue?

0

What do you mean by "column of DeparturePlace"... DeparturePlace is a column name which contains names of airports.

In DropdownList1 there items there are the names of airports also, so when e.g the user selects Johannesburg airport, i want my gridview to display ony the data where there is Johannesburg in the departure place column.

0

Well that's better explanation of the problem than simply pasting code.

Use this:

WHERE DeparturePlace [B]LIKE [/B]@DeparturePlace AND DestinationLoc [B]LIKE [/B]@DestinationLoc

Instead of this:

WHERE DeparturePlace = @DeparturePlace AND DestinationLoc = @DestinationLoc
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.