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);]

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

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

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.

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

dude
u could print out the sql query to get a clearer view of the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.