================================================================================
string sql ="select * from xxxxx where 1=1";
if( 條件a選了 )
{
sql = sql + " and a = XXXXX ";
}
if( 條件b選了 )
{
sql = sql + " and b = XXXXX ";
}
if( 條件c選了 )
{
sql = sql + " and c = XXXXX ";
}
if( 條件d選了 )
{
sql = sql + " and d = XXXXX ";
}
if( 條件e選了 )
{
sql = sql + " and e = XXXXX ";
}
if( 條件f選了 )
{
sql = sql + " and f = XXXXX ";
}
假設用戶選了 c e, 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and c=xxxxxx and e=XXXXXXX",
假設用戶只選了f , 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and f=xxxxxx ",
最后把這個sql放到資料庫里去查詢
uj5u.com熱心網友回復:
================================================================================
string sql ="select * from xxxxx where 1=1";
if( 條件a選了 )
{
sql = sql + " and a = XXXXX ";
}
if( 條件b選了 )
{
sql = sql + " and b = XXXXX ";
}
if( 條件c選了 )
{
sql = sql + " and c = XXXXX ";
}
if( 條件d選了 )
{
sql = sql + " and d = XXXXX ";
}
if( 條件e選了 )
{
sql = sql + " and e = XXXXX ";
}
if( 條件f選了 )
{
sql = sql + " and f = XXXXX ";
}
假設用戶選了 c e, 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and c=xxxxxx and e=XXXXXXX",
假設用戶只選了f , 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and f=xxxxxx ",
最后把這個sql放到資料庫里去查詢
================================================================================
string sql ="select * from xxxxx where 1=1";
if( 條件a選了 )
{
sql = sql + " and a = XXXXX ";
}
if( 條件b選了 )
{
sql = sql + " and b = XXXXX ";
}
if( 條件c選了 )
{
sql = sql + " and c = XXXXX ";
}
if( 條件d選了 )
{
sql = sql + " and d = XXXXX ";
}
if( 條件e選了 )
{
sql = sql + " and e = XXXXX ";
}
if( 條件f選了 )
{
sql = sql + " and f = XXXXX ";
}
假設用戶選了 c e, 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and c=xxxxxx and e=XXXXXXX",
假設用戶只選了f , 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and f=xxxxxx ",
最后把這個sql放到資料庫里去查詢
================================================================================
string sql ="select * from xxxxx where 1=1";
if( 條件a選了 )
{
sql = sql + " and a = XXXXX ";
}
if( 條件b選了 )
{
sql = sql + " and b = XXXXX ";
}
if( 條件c選了 )
{
sql = sql + " and c = XXXXX ";
}
if( 條件d選了 )
{
sql = sql + " and d = XXXXX ";
}
if( 條件e選了 )
{
sql = sql + " and e = XXXXX ";
}
if( 條件f選了 )
{
sql = sql + " and f = XXXXX ";
}
假設用戶選了 c e, 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and c=xxxxxx and e=XXXXXXX",
假設用戶只選了f , 那么最后的 sql就是
string sql ="select * from xxxx where 1=1 and f=xxxxxx ",
最后把這個sql放到資料庫里去查詢