access模糊查询 (急急急)
帮帮吧:
string Keyword = txtKeyword.Text.Trim().ToString();
string strSql = "select * from etw_product where p_name like '% " + Keyword + "% ' ";
//string strSql = "select * from etw_product where p_name like '%水晶瑪瑙% ' ";(这句也报错)
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ "xkConnStr "].ConnectionString);
OleDbDataAdapter cmd = new OleDbDataAdapter(strSql,cn);
cmd.SelectCommand.Parameters.Add( "? ", OleDbType.VarChar).Value = Keyword;
DataSet ds = new DataSet();
cn.Open();
cmd.Fill(ds);
cn.Close();
dtdproduct.DataSource = ds;
dtdproduct.DataBind();
运行:
异常详细信息: System.Data.OleDb.OleDbException: 内存溢出
源错误:
行 39: DataSet ds = new DataSet();
行 40: cn.Open();
行 41: cmd.Fill(ds);
行 42: cn.Close();
行 43:
源文件: f:\孙金\csj-china\index.aspx.cs 行: 41
堆栈跟踪:
[OleDbException (0x80004005): 内存溢出]
System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) +47
System.Data.OleDb.OleDbDataReader.GetRowHandles() +234
System.Data.OleDb.OleDbDataReader.ReadRowset() +38
System.Data.OleDb.OleDbDataReader.Read() +174
System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) +176
System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +176
System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +195
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +199
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +82
index.Button1_Click(Object sender, EventArgs e) in f:\孙金\csj-china\index.aspx.cs:41
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4926
[解决办法]
access和SqlServer不一样。
ACCESS库的通配符为:
* 与任何个数的字符匹配
? 与任何单个字母的字符匹配
SQL Server中的通配符为:
% 与任何个数的字符匹配
_ 与单个字符匹配
[解决办法]
或者你用这个试试
SELECT * FROM t_food WHERE t_food.name like '%%苹果%% '
[解决办法]
http://blog.csdn.net/CShapBoy/archive/2006/08/12/1053934.aspx