我或条款不起作用请帮助。 [英] My or clause is not working please help.

查看:89
本文介绍了我或条款不起作用请帮助。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码。或条件不满意

Hi
This is my code. or condition is not satisfying

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();
}

推荐答案

我们无法真正帮助那里:我们无法访问您的数据或价值观你加载到你的下降。它可以像状态在DropDownList1中,状态在DropDownList2中一样简单,或者(如Kornfeld所说),您的数据库中可能没有符合任何条件的数据。



所以在这一行上放一个断点:

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:
DataSet dsDetails = du.GetDataSet(qryDetails);

并查看查询。然后使用SSMS检查数据库并查看匹配的值。

如果有,则跳过GetDataSet调用,并查看它返回的表。

如果查询是正确的,并且数据库有数据,请再次执行,这次进入调用并按照该方法进行操作。



我们可以为你做。

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.


选择GatePassNo,CheckIN_Date,Customer_Name,State,

City,Customer_Location from Product_Details

其中( Customer_Name ='+ ddlCName.SelectedItem.Value +'

或State ='+ DropDownList2.SelectedItem.Value +'

或City ='+ DropDownList3.SelectedItem .Value +'

或Status ='+ DropDownList1.SelectedItem.Value +'

或GatePassNo ='+ ddlCGatePassNo.SelectedItem.Value +')



我不会批评你构建这个查询的方式,但至少它更好看。现在作为解决方案,也许其中一个下拉列表有空值?







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?



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 + "')");


这篇关于我或条款不起作用请帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆