使用C#在Access和SQL Server中构建模糊查询语句,类似(以Access为例): System.Data.OleDb.OleDbCommand oledbCmd = null;
System.Data.OleDb.OleDbDataReader oledbReader = null;
        System.Data.OleDb.OleDbConnection oledbConn = null;
成功建立数据库连接之后,构造查询
        string strSql = "select * from StaticAudit where cKey_1 Like '*Demo*'";
oledbCmd = oledbConn.CreateCommand();
oledbCmd.CommandText = strSql;
        oledbCmd.CommandType=CommandType.Text;
oledbReader = oledbCmd.ExecuteReader();
读取数据得时候没有数据啊,在Access和SQLServer中执行查询可以获取数据,用程序获取不了,谢谢啊,有分

解决方案 »

  1.   

    string temp = "";
    string strSql = String.Format("select * from StaticAudit where cKey_1 Like '%{0}%'",temp);
      

  2.   

    如果Demo是变量的话:
    string strSql = "select * from StaticAudit where cKey_1 Like '%"&Demo&"%'";
      

  3.   

    呵呵,兄弟们好像从前已经碰到过这种问题了呢,大家参考一下
    http://community.csdn.net/Expert/TopicView3.asp?id=4724403,
    我觉得应该是系统原因,估计得读到内存中再进行过滤了。