问题如下:
动态查询时,没有LIKE语句时,是正常的。但加入LIKE时就查不到了,而SQL语句在ACCESS中直接跑时,是可以查出数据的,为什么呢?
程序代码:
public DataSet queryList(string strSql,OleDbConnection dbconn)
{
DataSet ds = null;
try
{
Console.WriteLine("strSql-->" + strSql); OleDbDataAdapter da = new OleDbDataAdapter(strSql, dbconn);
ds = new DataSet();
da.Fill(ds,CommonConstant.DB_DSFillName); this.CloseDBConn(dbconn);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
} return ds;
}
打印出的SQL:
select xmid,xmbh,xmmc,xfsj,wcsj,isok,bz from jx_db_task where 1=1 and xmmc like '*内蒙古*' and Format(xfsj,'yyyy-mm-dd 00:00:00') >= Format('2009-2-2 19:45:31','yyyy-mm-dd 00:00:00') and Format(xfsj,'yyyy-mm-dd 00:00:00') <= Format('2013-2-3 19:45:31','yyyy-mm-dd 00:00:00') and Format(wcsj,'yyyy-mm-dd 00:00:00') >= Format('2008-2-4 19:45:31','yyyy-mm-dd 00:00:00') and Format(wcsj,'yyyy-mm-dd 00:00:00') <= Format('2013-2-7 19:45:31','yyyy-mm-dd 00:00:00')accesssqlC# WINFORM
动态查询时,没有LIKE语句时,是正常的。但加入LIKE时就查不到了,而SQL语句在ACCESS中直接跑时,是可以查出数据的,为什么呢?
程序代码:
public DataSet queryList(string strSql,OleDbConnection dbconn)
{
DataSet ds = null;
try
{
Console.WriteLine("strSql-->" + strSql); OleDbDataAdapter da = new OleDbDataAdapter(strSql, dbconn);
ds = new DataSet();
da.Fill(ds,CommonConstant.DB_DSFillName); this.CloseDBConn(dbconn);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
} return ds;
}
打印出的SQL:
select xmid,xmbh,xmmc,xfsj,wcsj,isok,bz from jx_db_task where 1=1 and xmmc like '*内蒙古*' and Format(xfsj,'yyyy-mm-dd 00:00:00') >= Format('2009-2-2 19:45:31','yyyy-mm-dd 00:00:00') and Format(xfsj,'yyyy-mm-dd 00:00:00') <= Format('2013-2-3 19:45:31','yyyy-mm-dd 00:00:00') and Format(wcsj,'yyyy-mm-dd 00:00:00') >= Format('2008-2-4 19:45:31','yyyy-mm-dd 00:00:00') and Format(wcsj,'yyyy-mm-dd 00:00:00') <= Format('2013-2-7 19:45:31','yyyy-mm-dd 00:00:00')accesssqlC# WINFORM
“LIKE 的标准用法是 like '%bd%' , ANSI的标准中是用%作为通配符,而微软总喜欢标新立异和别人不一样,所以用了 *”今天早上我遇到同样的问题,但我是在C++Builder2009中使用ADO连接Access数据据时,发现LIKE查询需要用%通配符而不是*。如果此答案采纳,请向ACMAIN_CHM大神致敬。