Usuário com melhor resposta
Error reporting The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect ?

Pergunta
-
In C # .net when running an SQL query to get access data with an error The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect, the problem is incorrect:
[code]
SELECT COUNT (MAPB) AS Count
FROM TABNHANVIEN
WHERE (HIENAN = 'True') AND (MAPB = 3)
GROUP BY MAPB;
[/ code]
But I copy this query directly to the microsoft access sql query to run normally, with no error, I run another query in C#.Net running normally, no error like this message, you know what is wrong is not ?sexta-feira, 14 de agosto de 2020 04:24
Respostas
-
Just for kicks, can you use a different name for your count column, say
SELECT COUNT(MAPB) AS cntMapB FROM TABNHANVIEN WHERE HIENAN = 'True' AND MAPB = 3;
Also, since you're using static single value for MAPB, you may omit GROUP BY.
Looking for new opportunities
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
sexta-feira, 14 de agosto de 2020 04:47 -
Hi lamtriendong,
Do you try to change Count to Count1 or change other column names to others to test again?
Is the issue solved?
BR,
Mia
If the reply is helped, please "Mark Answer" and upvote it.--Mia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
segunda-feira, 17 de agosto de 2020 01:18 -
Hi lamtriendong,
Do you try to change Count to Count1 or change other column names to others to test again?
Is the issue solved?
BR,
Mia
If the reply is helped, please "Mark Answer" and upvote it.--Mia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
terça-feira, 18 de agosto de 2020 01:07
Todas as Respostas
-
Just for kicks, can you use a different name for your count column, say
SELECT COUNT(MAPB) AS cntMapB FROM TABNHANVIEN WHERE HIENAN = 'True' AND MAPB = 3;
Also, since you're using static single value for MAPB, you may omit GROUP BY.
Looking for new opportunities
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
sexta-feira, 14 de agosto de 2020 04:47 -
Hi Iamtriendong,
> But I copy this query directly to the microsoft access sql query to run normally, with no error, I run another query in C#.Net running normally, no error like this message, you know what is wrong is not
I think sql query's syntax is correct. You just need to verify the spelling of the column names or parameters in your query. Modify the code as next and test again:
SELECT COUNT (MAPB) AS Count FROM TABNHANVIEN WHERE (HIENAN <> 'True') AND (MAPB = 1) GROUP BY MAPB;
or Replace the column name MAPB with other column name to test.
SELECT COUNT (OtherColumnName) AS Count FROM TABNHANVIEN WHERE (HIENAN <> 'True') AND (OtherColumnName = XX) GROUP BY OtherColumnName;
I test with c# .net4.6.1 it works ok, code as next, you can copy it and then change the server’s name and database's name and then use your query string to test. Test on my side: sql version: sql2019 database: AdventureWorks2016
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; namespace TestApp1 { class Program { static void Main(string[] args) { string connString = @"Server =BI\SQL2019DB; Database = Adventureworks2016; Trusted_Connection = True;"; try { using (SqlConnection conn = new SqlConnection(connString)) { //retrieve the SQL Server instance version string query = @"SELECT Count(JobTitle) As Count FROM HumanResources.Employee WHERE ( Gender <> 'M') and (JobTitle = 'Design Engineer') GROUP BY JobTitle; "; SqlCommand cmd = new SqlCommand(query, conn); //open connection conn.Open(); //execute the SQLCommand SqlDataReader dr = cmd.ExecuteReader(); //check if there are records if (dr.HasRows) { while (dr.Read()) { //display retrieved record (first column only/string value) Console.WriteLine(dr.GetInt32(0)); } } else { Console.WriteLine("No data found."); } dr.Close(); } } catch (Exception ex) { //display error message Console.WriteLine("Exception: " + ex.Message); } } } }
More information: querying-sql-server-tables-from-net
BR,
Mia
If the reply helped, please "Mark Answer" and upvote it.--Mia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- Editado MIAOYUXI sexta-feira, 14 de agosto de 2020 07:44
sexta-feira, 14 de agosto de 2020 07:42 -
The SELECT statement includes a reserved word or
You used COUNT as column alias and that's a ODBC Reserved KeywordOlaf Helper
[ Blog] [ Xing] [ MVP]sexta-feira, 14 de agosto de 2020 07:55 -
Hi lamtriendong,
Do you try to change Count to Count1 or change other column names to others to test again?
Is the issue solved?
BR,
Mia
If the reply is helped, please "Mark Answer" and upvote it.--Mia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
segunda-feira, 17 de agosto de 2020 01:18 -
Hi lamtriendong,
Do you try to change Count to Count1 or change other column names to others to test again?
Is the issue solved?
BR,
Mia
If the reply is helped, please "Mark Answer" and upvote it.--Mia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:27
- Não Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 07:49
- Marcado como Resposta lamtriendong terça-feira, 25 de agosto de 2020 08:17
terça-feira, 18 de agosto de 2020 01:07 -
The above statement got an error on C#.NET of access, I tried it in C#.NET SQL Server to run normally but in C#.NET of access it did not let the alias match the COUNT statement, thank you for answering my question, now the above command is running well after I renamed the alias Count to Count1 or name else
- Editado lamtriendong terça-feira, 25 de agosto de 2020 08:17
terça-feira, 25 de agosto de 2020 07:27