点击新增条件,复制控件
public DataTable QueryInventoryInfo(string productId, string productName, string categoryName)
{
string sql = "select ProductId,ProductName,Unit,UnitPrice,Discount,TotalCount,MaxCount,MinCount,InventoryStatus,CategoryName,CategoryId ";
sql += "from view_QueryInventoryInfo where 1=1";
if (productId.Length != 0)
{
sql += string.Format(" and ProductId='{0}'", productId);
}
if (productName.Length != 0)
{
sql += string.Format(" and ProductName like '%{0}%'", productName);
}
if(categoryName.Length !=0)
{
sql += string.Format(" and CategoryName ='{0}'",categoryName);
}
return SQLHelper.GetDataSet(sql).Tables[0];
}
试用这个办法
对联动的下拉框,就是做selectchanged事件做触发后填充。
添加条件,就是拼凑查询条件。如果是存储过程,也差不多类似,只不过对没有用到的条件做“where 1=1"的 判断。
sql拼接吧
sql="select * from 表 where 1=1";//没有查询条件的时候
有查询条件的时候在if判断中写:sql+=" and 查询条件";