0

我正在使用 Visual Studio 2008 用 C# 编写程序,从.sdf文件中检索数据时出错

解析查询时出错SqlCeConnection

我的代码是

SqlCeConnection conn = new SqlCeConnection(connStr);
SqlCeCommand cmd = new SqlCeCommand();
DataSet ds = new DataSet();
SqlCeDataAdapter da;

try
{
    conn.Open();
    cmd = conn.CreateCommand();

    if(mode == "update")
       cmd.CommandText = "SELECT eq_id, description, bl_id, fl_id,  rm_id, modelno, category, eq_std, comments FROM eq where (isModified = 1) SELECT * FROM eq_log";
    else if(mode == "create")
       cmd.CommandText = "SELECT eq_id, description, bl_id, fl_id, rm_id, modelno, category, eq_std, comments FROM eq where (isModified = 2) SELECT * FROM eq_log";

    da = new SqlCeDataAdapter(cmd);
    da.Fill(ds);

    return ds;
}
catch (Exception db)
{
}

错误是:

解析查询时出错。[令牌行号 = 2,令牌行偏移量 = 1,错误中的令牌 = SELECT]

异常详细信息:System.Data.SqlServerCe.SqlCeException:解析查询时出错。解析查询时出错。[ 令牌行号 = 2,令牌行偏移量 = 1,错误令牌 = SELECT

4

2 回答 2

0

使用 SQL Server Compact,每个命令只能有一个 SELECT,因此必须返回两个 DataSets/DataTables

于 2013-05-24T09:30:59.000 回答
0

您在 cmd.CommandText 中有 2 个选择语句。您需要将它们分开;

SqlCeConnection conn = new SqlCeConnection(connStr);
SqlCeCommand cmd = new SqlCeCommand();
DataSet ds = new DataSet();
SqlCeDataAdapter da;

try
{
    conn.Open();
    cmd = conn.CreateCommand();

    if(mode == "update")
       cmd.CommandText = "SELECT eq_id, description, bl_id, fl_id,  rm_id, modelno, category, eq_std, comments FROM eq where (isModified = 1); SELECT * FROM eq_log";
    else if(mode == "create")
       cmd.CommandText = "SELECT eq_id, description, bl_id, fl_id, rm_id, modelno, category, eq_std, comments FROM eq where (isModified = 2); SELECT * FROM eq_log";

    da = new SqlCeDataAdapter(cmd);
    da.Fill(ds);

    return ds;
}
catch (Exception db)
{
}

告诉我这是否适合你。

于 2013-05-24T07:03:57.183 回答