关于C#中用access做数据库,使用like语句的问题

来源:互联网 发布:linux开机自启动命令 编辑:程序博客网 时间:2024/05/29 16:47

做了WindowForm程过程中,用到access做数据库。在其中用到一条SQL语句 "select * from table where A like 'b*'"。返回结果中没有一条。但是在access中的查询中,运行此语句却能返回结果。
 最后在程序中需要把*换成%
  StringBuilder sqlStr=new StringBuilder();
    sqlStr.Append( "select  COUNT(*) ");
    sqlStr.Append(" from ").Append(tableName);
    sqlStr.Append(" where " ).Append(tableName);
    sqlStr.Append("_Name");
    sqlStr.Append("='");
    sqlStr.Append(namestr);
    sqlStr.Append(" ' and ");
    sqlStr.Append(tableName);
    sqlStr.Append("_SORT LIKE '%B'");
才能返回非零结果.

try
   {
    int count = -1;
    dbop=new DatabaseOp(tablePath);

    string strSql=StrCheckName(TitleTableName,namestr);
    object obj = dbop.GetFirstValue(strSql);

    if (obj!=null)
    {
     count = System.Convert.ToInt32(obj);
    }
    return count;
   }
   catch(Exception ex)
   {
    throw ex;
   }
   finally
   {
    if (dbop!=null)
    {
     dbop.Close();
    }
   }

原文地址:http://www.cnblogs.com/flashicp/archive/2007/03/19/679991.html

阅读全文
0 0
原创粉丝点击