C#中count(*)的正确查询是什么? [英] What will be the right query for count(*) in C#?
本文介绍了C#中count(*)的正确查询是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果数据已经存在于数据库中,这是我的计数代码显示错误
This my count code to display error if the data is already exists in database
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM tbl_register WHERE ([Email_Id] = @Email_Id)", con);
并且错误显示如下:
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行'[Email_Id] = @Email_Id)附近使用正确的语法
我是什么尝试过:
我尝试了类似条款。
这是通过添加参数
AND the ERROR is showing like this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Email_Id] = @Email_Id)' at line 1
What I have tried:
I have tried like clause.
this is done by adding parameters
推荐答案
您使用的是MySQL,而不是Microsoft SQL Server。因此,这些方括号不能用于转义字段名称。在MySQL中,您使用反引号`
。但无论如何,你不需要在这里转义字段名称,它不是保留字,也不包含空格。
You use MySQL, not Microsoft SQL Server. Consequently, those square brackets cannot be used for escaping field names. In MySQL, you use backticks `
instead. But anyway, you do not need to escape the field name here, it is not a reserved word nor does it contain spaces.
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM tbl_register WHERE (Email_Id = @Email_Id)", con);
另外,请确保您在 Email_Id
上有索引。
Also, make sure you have an index on Email_Id
.
这篇关于C#中count(*)的正确查询是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文