我正在使用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
答案 0 :(得分:0)
cmd.CommandText中有2个select语句。您需要通过 ;
分隔它们。
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)
{
}
告诉我这是否适合你。
答案 1 :(得分:0)
对于SQL Server Compact,每个命令只能有一个SELECT,因此必须返回两个DataSet / DataTables