1

i'm pretty new to ADO.NET using C# (Visual Studio 2010). Using LinqToSql isn't an option because underlying database is a Compact Edition 3.5 (unfortunealty).

with the code displayed underneath I get an error: "There was an error parsing the query. [ Token line number = 2,Token line offset = 38,Token in error = AgentName ]"

Can someone tell me what i'm doing wrong?

 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();
2
  • Did you try to execute the query without column aliases or did you try to change the aliases to 'col1', 'col2', ...? Commented Sep 27, 2011 at 8:50
  • Linq to SQL works with SQL Server Compact 3.5 (using sqlmetal.exe from command line) Commented Sep 27, 2011 at 8:52

2 Answers 2

4

i think you need to lose the quotes around 'AgentName'.

Sign up to request clarification or add additional context in comments.

Comments

1

Change single quotes '' to brackets []

a.name as [AgentName],

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.