Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
This is my code. or condition is not satisfying
C#
public void populate()
{
  string qryDetails = "select GatePassNo, CheckIN_Date,Customer_Name,State,City,Customer_Location from Product_Details where  ( Customer_Name='"+ddlCName.SelectedItem.Value+"' or State='"+DropDownList2.SelectedItem.Value+"' or City='"+DropDownList3.SelectedItem.Value+"' or Status='"+DropDownList1.SelectedItem.Value+"' or GatePassNo='"+ddlCGatePassNo.SelectedItem.Value+"')";
  DataSet dsDetails = du.GetDataSet(qryDetails);

  GridView2.DataSource = dsDetails;
  GridView2.DataBind();
}
Posted
Updated 10-Jun-14 2:28am
v2
Comments
Kornfeld Eliyahu Peter 10-Jun-14 8:30am    
So? You may have no data for that specific condition!
Also you are on a total wrong way of building queries in ADO.NET - go and learn about parametrized queries...

We can't really help there: we don;t have access to your data, or the values you load into your drop downs. It could be as simple as the "State is in DropDownList1 and Status is in DropDownList2" or (as Kornfeld says) there may be no data in your DB which matches any of those conditions.

So put a breakpoint on the line:
C#
DataSet dsDetails = du.GetDataSet(qryDetails);
and look at the query. Then use SSMS to examine your database and see what values you have that match.
If there are any, then step over the GetDataSet call, and look at the tables it returns.
If the query is right, and the database has teh data, do it again, and this time step into teh call and follow through that method.

We can't do it for you.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 10-Jun-14 8:47am    
Did you have lunch? You should have one, while I'm going to fix all your typo :laugh: :laugh: :laugh:
goathik 10-Jun-14 9:24am    
You should also blame mr. OriginalGriff, for he also pointed our friend to keep trying to run the dangerous query he has written, until he gets it working.
Kornfeld Eliyahu Peter 10-Jun-14 9:25am    
Do not afraid I do blame him too... :-)
goathik 10-Jun-14 9:26am    
¬¬
select GatePassNo, CheckIN_Date,Customer_Name,State,
City,Customer_Location from Product_Details
where ( Customer_Name='"+ddlCName.SelectedItem.Value+"'
or State='"+DropDownList2.SelectedItem.Value+"'
or City='"+DropDownList3.SelectedItem.Value+"'
or Status='"+DropDownList1.SelectedItem.Value+"'
or GatePassNo='"+ddlCGatePassNo.SelectedItem.Value+"')

I'll not criticize the way you are building this query, but at least it is better looking that way. Now as a solution, perhaps there is a null value on one of those dropdowns?



C#
string sql = "select GatePassNo, CheckIN_Date,Customer_Name,State, " +
 "City,Customer_Location from Product_Details " +
  "where ( 1=1 " +
  ddlCName.SelectedItem.Value != null ? " " : ("or Customer_Name='" + ddlCName.SelectedItem.Value + "' ") +
  DropDownList2.SelectedItem.Value != null ? " " : ("or State='" + DropDownList2.SelectedItem.Value + "' ") +
  DropDownList3.SelectedItem.Value != null ? " " : ("or City='" + DropDownList3.SelectedItem.Value + "' ") +
  DropDownList1.SelectedItem.Value != null ? " " : ("or Status='" + DropDownList1.SelectedItem.Value + "' ") +
  ddlCGatePassNo.SelectedItem.Value != null ? " " : ("or GatePassNo='" + ddlCGatePassNo.SelectedItem.Value + "')");
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 10-Jun-14 8:53am    
'I'll not criticize the way you are building this query' - Why?! What else can you do with it?
goathik 10-Jun-14 9:01am    
that query can work, even tho it is not the best way to write it. the problem he stated has nothing to do with the beauty of his code
Kornfeld Eliyahu Peter 10-Jun-14 9:05am    
Ever heard of 'sql injection' - also that can work in such a query...
goathik 10-Jun-14 9:12am    
I do, but that is another issue. according to his project scenario, perhaps he won't need security at all.
Whatever... hope i helped him solving the problem he STATED.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900