OleDbDataAdapter 查询带条件就导致DataSet的Table[0]中无数据
我用的是vs2003
请看以下代码:
/// <summary>
/// 获取适合当前子类的DataAdapter实例
/// </summary>
/// <param name= "SQLString "> 构造该实例的SQL语句参数 </param>
/// <returns> </returns>
override protected System.Data.OleDb.OleDbDataAdapter GetDataAdapter(string SQLString)
{
System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(SQLString, dbConn as OleDbConnection);
if (inTran) da.SelectCommand.Transaction = dbTran as OleDbTransaction;
return da as System.Data.OleDb.OleDbDataAdapter;
}
virtual public DataTable ExecuteQuery(string SQLString)
{
DataSet ds = new DataSet();
System.Data.OleDb.OleDbDataAdapter da = GetDataAdapter(SQLString);
try
{
da.Fill(ds);
return ds.Tables[0];
}
catch(Exception ex)
{
if (DBAccessOnError != null) DBAccessOnError(ex, SQLString, null);
return null;
}
}
如果SQLString=“select floors from ipmac”就能得到ds.Tables[0],ds.Tables[0].Rows=4
如果SQLString=“select floors from ipmac where Regional like '*第1区域* '”就不能得到ds.Tables[0],ds.Tables[0].Rows.count=0
其中以下语句在Access2003中执行查询
select floors from ipmac where Regional like '*第1区域* '
可获得2条记录
------解决方案--------------------SQLString=“select floors from ipmac where Regional like '*第1区域* '
====================================================================
SQLString=“select floors from ipmac where Regional like '%第1区域% '