本文介绍了如何使用不同的搜索条件从数据酶中选择记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用不同的搜索条件从数据酶中选择记录.
how to select records from dataase using different search criteria.
推荐答案
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 + "%'";
}
这篇关于如何使用不同的搜索条件从数据酶中选择记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!