各位大侠,帮咱看个问题,看哪出问题了。急求解,谢谢
        public DataTable GetLicsByYM(string str,string value) {
            SQLiteHelper dbc = new SQLiteHelper();
            string sql = "select * from tb_License where " + str + "='" + value.Trim() + "'";
            DataTable dt = dbc.Query(sql, "table");
            return dt;
        }
这是SQLiteHelper里边函数
        public DataTable Query(string SQLString, string TableName)
        {
            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                try
                {
                    connection.Open();
                    SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
                    command.Fill(ds);
                    dt = ds.Tables[0];
                }
                catch (System.Data.SQLite.SQLiteException ex)
                {
                    throw new Exception(ex.Message);
                }
                return dt;
            }
        }
这儿是调用。
DataTable dt=GetLicsByYM("substr(date,0,8)", t_txtNum.ToString().Trim());
问题就是执行带函数据sql语句时查不出数据来。总是0行数据
不过,执行查询全部数据时挺正常的。郁闷中……
代码分在几个文件中,只放几个必要的,需要的话,回帖再贴

解决方案 »

  1.   

      DataTable dt = dbc.Query(sql, "table");這個"table"是啥?連接字符串?
      

  2.   

    table 應該使用實際的表名吧
      

  3.   

    是传进去的表名,用于填充dataset
      

  4.   

            public DataTable Query(string SQLString, string TableName)
            {
                using (SQLiteConnection connection = new SQLiteConnection(connectionString))
                {
                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable();
                    try
                    {
                        connection.Open();
                        SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
                        //command.Fill(ds, TableName);
                        command.Fill(ds);
                        dt = ds.Tables[0];
                    }
                    catch (System.Data.SQLite.SQLiteException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    return dt;
                }
            }
    函数是这样儿的
      

  5.   

    str + "='" + value.Trim() + "'";
    这里的单引号 你的好像是中文式的 改成英文式的看看呢?
      

  6.   

    不是引号的问题,好像是date字段名有问题,但是我把它换成了dates,好像还是查不出数据来,也不知道是为嘛?