如何使用不同的搜索条件从数据酶中选择记录. [英] how to select records from dataase using different search criteria.
本文介绍了如何使用不同的搜索条件从数据酶中选择记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用不同的搜索条件从数据酶中选择记录.
how to select records from dataase using different search criteria.
推荐答案
像这样吗?
LINQ和运行时的动态谓词构建 [ ^ ]
我假设您正在使用LINQ to SQL,因为您没有提供任何详细信息.
Like this?
LINQ and Dynamic Predicate Construction at Runtime[^]
I assume you''re using LINQ to SQL since you''re not giving any details.
Try to Build Your Query Like below
string sql = "select * from tablname where 1=1";
if (txtSearchRiskId.Text != "")
{
sql += "fRiskID ='" + txtSearchRiskId.Text + "' and ";
}
if (txtsearchrisksequenceno.Text != "")
{
sql += "fSerialNo like'%" + txtsearchrisksequenceno.Text + "%'and ";
}
if (txtsearchriskplateno.Text != "")
{
sql += "fPlateNo like'%" + txtsearchriskplateno.Text + "%' or fPlateNo_bl like'%" + txtsearchriskplateno.Text + "%'and ";
}
if (txtsearchriskyear.Text != "")
{
sql += "fYear like'%" + txtsearchriskyear.Text + "%'and ";
}
if (txtsearchriskchassisno.Text != "")
{
sql += "fChassisNo like'%" + txtsearchriskchassisno.Text + "%'and ";
}
if (txtsearchriskcustomid.Text != "")
{
sql += "fCustomID like'%" + txtsearchriskcustomid.Text + "%'and ";
}
if (ddlsearchRiskTypeCodevalue.SelectedIndex > 0)
{
sql += "fVehicleTypevalue like'%" + ddlsearchRiskTypeCodevalue.SelectedItem.Value + "%'and ";
}
if (ddlsearchRiskmakevalue.SelectedIndex > 0)
{
sql += "fMakevalue like'%" + ddlsearchRiskmakevalue.SelectedItem.Value + "%'and ";
}
if (ddlsearchRiskmodelvalue.SelectedIndex > 0)
{
sql += "fModelvalue like'%" + ddlsearchRiskmodelvalue.SelectedItem.Value + "%'";
}
这篇关于如何使用不同的搜索条件从数据酶中选择记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文