Sqlce {“解析查询时出错。[令牌行号= 1,令牌行偏移= 27,令牌错误= CONTAINS]”}

时间:2014-06-10 05:23:57

标签: c# sql

我在Plant表SeedStartMonths中有一个字段作为nvarchar,包含1 2 4 11.我正在尝试SELECT * FROM Plant WHERE CONTAINS(SeedStartMonths,'11')并且它给了我错误。

    string tmp = ( (int) thisMonth ).ToString();
            using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM Plant WHERE CONTAINS(SeedStartMonths, '" + tmp + "')", con))
            {
                SqlCeDataReader reader = com.ExecuteReader();

                while (reader.Read())
                {
                    try
                    {

                        AddReaderToGardenEntityList(gardenEntities, reader);
                    }
                    catch (Exception)
                    {
                        //unable to parse datas
                    }
                }
            }

1 个答案:

答案 0 :(得分:0)

SQL-CE不支持CONTAINS谓词函数。但它确实支持LIKE运算符,您必须像这样重写查询:

SELECT * FROM Plant WHERE SeedStartMonths LIKE '%11%'