gpt4 book ai didi

c# - 使用 C# 执行 SQLCommand 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:01 27 4
gpt4 key购买 nike

我是使用 C# (Visual Studio 2010) 的 ADO.NET 的新手。使用 LinqToSql 不是一种选择,因为底层数据库是 Compact Edition 3.5(不幸)。

下面显示的代码出现错误:“解析查询时出错。[ token 行号 = 2, token 行偏移量 = 38,错误 token = AgentName]”

谁能告诉我我做错了什么?

 using (SqlCeConnection oConn = new SqlCeConnection(connectionstring))
{
string strSql = @"select
a.name as 'AgentName',
t.description as 'JobType',
s.description as 'Status',
count(j.statusid) as 'Count'
from
jobs as j
inner join agents as a on j.agentid = a.id
inner join statusdictionary as s on j.statusid = s.id
inner join jobtypedictionary as t on j.jobtypeid = t.id
where
convert(datetime,starttime,0) between @FirstDate and @LastDate
AND j.JobTypeID = @JobTypeID AND j.AgentID = @AgentID
group by
s.description,
t.description,
a.name order by a.name,
t.description";
SqlCeCommand oCmd = new SqlCeCommand(strSql, oConn);

SqlCeParameter fdparam = new SqlCeParameter();
fdparam.ParameterName = "@FirstDate";
fdparam.Value = firstdate;
oCmd.Parameters.Add(fdparam);

SqlCeParameter ldparam = new SqlCeParameter();
ldparam.ParameterName = "@LastDate";
ldparam.Value = lastdate ;
oCmd.Parameters.Add(ldparam);

SqlCeParameter JIDparam = new SqlCeParameter();
JIDparam.ParameterName = "@JobTypeID";
JIDparam.Value = jobtypeid;
oCmd.Parameters.Add(JIDparam);

SqlCeParameter AIDparam = new SqlCeParameter();
AIDparam.ParameterName = "@AgentID";
AIDparam.Value = jobtypeid;
oCmd.Parameters.Add(AIDparam);

oConn.Open();
SqlCeDataReader oReader = oCmd.ExecuteReader();

最佳答案

我认为您需要去掉“AgentName”周围的引号。

关于c# - 使用 C# 执行 SQLCommand 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7566390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com