關于C#中用access做數據庫,使用like語句的問題(轉)
關于C#中用access做數據庫,使用like語句的問題
作者:flashicp 來源:博客園 發布時間:2007-03-19 16:24 原文鏈接 [收藏]
做了WindowForm程過程中,用到access做數據庫。在其中用到一條SQL語句 "select * from table where A like 'b*'"。返回結果中沒有一條。但是在access中的查詢中,運行此語句卻能返回結果。
最后在程序中需要把*換成%
才能返回非零結果.
代碼
StringBuilder sqlStr=new StringBuilder();
sqlStr.Append( "select COUNT(*) ");
sqlStr.Append(" from ").Append(tableName);
sqlStr.Append(" where " ).Append(tableName);
sqlStr.Append("_Name");
sqlStr.Append("='");
sqlStr.Append(namestr);
sqlStr.Append(" ' and ");
sqlStr.Append(tableName);
sqlStr.Append("_SORT LIKE '%B'");
try
{
int count = -1;
dbop=new DatabaseOp(tablePath);
string strSql=StrCheckName(TitleTableName,namestr);
object obj = dbop.GetFirstValue(strSql);
if (obj!=null)
{
count = System.Convert.ToInt32(obj);
}
return count;
}
catch(Exception ex)
{
throw ex;
}
finally
{
if (dbop!=null)
{
dbop.Close();
}
}

浙公網安備 33010602011771號