3个回答
展开全部
string strSql="select * from 表 where 1=1 ";
if(品种!="")<<<<这个表示品种不限,你需要按实际自己微调
{
strSql=strSql+" and 品种 = ‘“+品种+”’ ";
}
if(颜色!="")
{
strSql=strSql+" and 颜色 = ‘“+颜色+”’ ";
}
重量,形状,价格 一样往下面拼接
最后查出来的就是多条件了
if(品种!="")<<<<这个表示品种不限,你需要按实际自己微调
{
strSql=strSql+" and 品种 = ‘“+品种+”’ ";
}
if(颜色!="")
{
strSql=strSql+" and 颜色 = ‘“+颜色+”’ ";
}
重量,形状,价格 一样往下面拼接
最后查出来的就是多条件了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public DataSet GetBooks(string ISBN, string Name, string State,string Attrition, string Writer,string Type, string Press,string Bid)
{
string strSql = "select * from tb_BookStorage,tb_BooksInfo,tb_Cip,tb_Press where 1=1";
strSql += ISBN == "" ? "" : "and tb_BooksInfo.ISBN like '%'+@ISBN+'%'";
strSql += Name == "" ? "" : "and tb_BooksInfo.Name like '%'+@Name+'%'";
strSql += State == "" ? "" : "and tb_BookStorage.State like '%'+@State+'%'";
strSql += Attrition == "" ? "" : "and tb_BookStorage.Status like '%'+@Status+'%'";
strSql += Writer == "" ? "" : "and tb_BooksInfo.Writer like '%'+@Writer+'%'";
strSql += Type == "" ? "" : "and tb_Cip.Cname like '%'+@Type+'%'";
strSql += Press == "" ? "" : "and tb_Press.Pname like '%'+@Press+'%'";
strSql += Bid == "" ? "" : "and tb_BookStorage.Bid like '%'+@Bid+'%'";
strSql += "and tb_BooksInfo.ISBN=tb_BookStorage.ISBN and tb_BooksInfo.Pid=tb_Press.Pid and tb_BooksInfo.Cid=tb_Cip.Cid and tb_BookStorage.Status < 3";
SqlParameter[] para ={
new SqlParameter("@ISBN",ISBN),
new SqlParameter("@Name",Name),
new SqlParameter("@State",State),
new SqlParameter("@Status",Attrition),
new SqlParameter("@Writer",Writer),
new SqlParameter("@Type",Type),
new SqlParameter ("@Press",Press),
new SqlParameter ("@Bid",Bid)
};
DataSet ds = help.GetDataSelect(strSql, para);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
return ds;
}
else
{
return null;
}
}
你可以参考下,这是多表多条件查询
{
string strSql = "select * from tb_BookStorage,tb_BooksInfo,tb_Cip,tb_Press where 1=1";
strSql += ISBN == "" ? "" : "and tb_BooksInfo.ISBN like '%'+@ISBN+'%'";
strSql += Name == "" ? "" : "and tb_BooksInfo.Name like '%'+@Name+'%'";
strSql += State == "" ? "" : "and tb_BookStorage.State like '%'+@State+'%'";
strSql += Attrition == "" ? "" : "and tb_BookStorage.Status like '%'+@Status+'%'";
strSql += Writer == "" ? "" : "and tb_BooksInfo.Writer like '%'+@Writer+'%'";
strSql += Type == "" ? "" : "and tb_Cip.Cname like '%'+@Type+'%'";
strSql += Press == "" ? "" : "and tb_Press.Pname like '%'+@Press+'%'";
strSql += Bid == "" ? "" : "and tb_BookStorage.Bid like '%'+@Bid+'%'";
strSql += "and tb_BooksInfo.ISBN=tb_BookStorage.ISBN and tb_BooksInfo.Pid=tb_Press.Pid and tb_BooksInfo.Cid=tb_Cip.Cid and tb_BookStorage.Status < 3";
SqlParameter[] para ={
new SqlParameter("@ISBN",ISBN),
new SqlParameter("@Name",Name),
new SqlParameter("@State",State),
new SqlParameter("@Status",Attrition),
new SqlParameter("@Writer",Writer),
new SqlParameter("@Type",Type),
new SqlParameter ("@Press",Press),
new SqlParameter ("@Bid",Bid)
};
DataSet ds = help.GetDataSelect(strSql, para);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
return ds;
}
else
{
return null;
}
}
你可以参考下,这是多表多条件查询
更多追问追答
追问
问下啊。我也没的那些 条件都是a标签,怎么判断选择的是哪个呢,
追答
a标签是没有值给你取的~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
整个不是很简单吗?选择一种,如果是前部 则where语句不做限制,如果选择了一种,那么就加个限制,比如我们数据库表字段颜色叫Color,加个小于1000 则where Color='Red' and Price<1000。还不明白可以加我q
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询