问题描述
我从我的Web应用程序和访问2007查询向导执行下面的查询。而我得到两个不同的结果。
SELECT R.Rept_Name,D.Dist_Name,S.State_Name FROM(tblReporter为R LEFT JOIN tblDist AS D ON R.Dist_Id = D.Dist_Id)LEFT JOIN tblState为S在S .State_Id = R.State_Id WHERE R.Rept_Name LIKE'*镭*'ORDER BY R.Rept_Name;
从Web应用程序
结果是0行,并从查询向导2 rows.If我删除where条件比这两结果相同。请帮我什么是错的查询。如果任何其他信息需要请告诉我。
Web应用程序code ...
公开数据表getRept(字符串REPT,串mobno)
{
DataTable的DT =新的DataTable();
使用(康涅狄格州的OleDbConnection =新的OleDbConnection(的getConnection()))
{
使用(OleDbCommand的CMD = conn.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText =SELECT R.Rept_Name,D.Dist_Name,S.State_Name FROM(tblReporter为R LEFT JOIN tblDist AS D ON R.Dist_Id = D.Dist_Id)LEFT JOIN tblState为S ON S.State_Id = R.State_Id WHERE R.Rept_Name LIKE'*+ REPT +*ORDER BY R.Rept_Name;;
conn.Open();
使用(OleDbDataReader SDR = cmd.ExecuteReader())
{
如果(sdr.HasRows)
dt.Load(SDR);
} }
}
返回DT;
}
您越来越绊倒通过在访问本身运行的查询和查询之间的LIKE通配符的区别从外部应用程序运行。
在运行从Access本身,您需要使用星号作为通配符查询: LIKE'*镭*'
在运行从外部应用程序的查询(如您的C#应用程序),您需要使用百分号作为通配符: LIKE'%镭%
I am executing following query from my web application and access 2007 query wizard. And I am getting two different result.
SELECT R.Rept_Name, D.Dist_Name,S.State_Name FROM (tblReporter AS R LEFT JOIN tblDist AS D ON R.Dist_Id=D.Dist_Id) LEFT JOIN tblState AS S ON S.State_Id=R.State_Id WHERE R.Rept_Name LIKE '*Ra*' ORDER BY R.Rept_Name;
Result from web application is with 0 rows and from query wizard 2 rows.If I remove where condition than both result are same. Please help me what is wrong with query. If any other info require please tell me.
Web application code ...
public DataTable getRept(string rept, string mobno)
{
DataTable dt = new DataTable();
using (OleDbConnection conn = new OleDbConnection(getConnection()))
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT R.Rept_Name, D.Dist_Name,S.State_Name FROM (tblReporter AS R LEFT JOIN tblDist AS D ON R.Dist_Id=D.Dist_Id) LEFT JOIN tblState AS S ON S.State_Id=R.State_Id WHERE R.Rept_Name LIKE '*" + rept + "*' ORDER BY R.Rept_Name;";
conn.Open();
using (OleDbDataReader sdr = cmd.ExecuteReader())
{
if (sdr.HasRows)
dt.Load(sdr);
}
}
}
return dt;
}
You are getting tripped up by the difference in LIKE wildcard characters between queries run in Access itself and queries run from an external application.
When running a query from within Access itself you need to use the asterisk as the wildcard character: LIKE '*Ra*'
.
When running a query from an external application (like your C# app) you need to use the percent sign as the wildcard character: LIKE '%Ra%'
.
这篇关于不同的结果通过我的应用程序和访问2007查询向导执行相同的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!