我的应用程序和访问查询向导之间的不同样的行为 [英] Different LIKE behaviour between my application and the Access query wizard

查看:102
本文介绍了我的应用程序和访问查询向导之间的不同样的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的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%'.

这篇关于我的应用程序和访问查询向导之间的不同样的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆