简体   繁体   English

Visual Studio 2010中Mysql中的错误

[英]Error in Mysql in Visual Studio 2010

I'm getting this error in Visual Studio 2010 C# project. 我在Visual Studio 2010 C#项目中遇到此错误。 I used the Mysql driver version 6.8.3.0 to made the connection to mysql server(which created via mysql workbench 6.1) and the connection to mysql server established successful(which created via visual studio) but error comes in this line when my software runs. 我使用版本6.8.3.0的Mysql驱动程序建立了到mysql服务器(通过mysql workbench 6.1创建)的连接,并成功建立了到mysql服务器(通过visual studio创建)的连接,但是当我的软件运行时,此行出现错误。 I search in the internet found that remote connection problem is the issue. 我在互联网上搜索发现是远程连接问题。 But if my connection established fine this cannot be the issue and according to the error its saying that some issue in sql query. 但是,如果我的连接建立良好,那么这将不是问题,并且根据错误说它在sql查询中存在问题。 But this is a simple select statement(SELECT * FROM case).Any solution or suggestion is appreciated. 但这是一个简单的select语句(SELECT * FROM case)。任何解决方案或建议都值得赞赏。

using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader()) in the following code section. 在下面的代码节中using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())

String connectionString = "server = localhost; user id = XXX; password = XXX;  database = XXXX";

        MySqlConnection connection = new MySqlConnection(connectionString);
        connection.Open();
        String searchString = "SELECT * FROM case" ;
         using (MySqlCommand mySqlCommand = new MySqlCommand(searchString, connection))
            {
                // mySqlCommand.Parameters.AddWithValue("@caseId", textBox1.Text);
                using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                {
                    String sb;
                    sb = mySqlDataReader.GetInt32(0).ToString();
                    MessageBox.Show(sb);

The part of error i'm getting is this. 我得到的部分错误是这样的。

 MySql.Data.MySqlClient.MySqlException was unhandled
 Message=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 'case' at line 1 
 Source=MySql.Data
ErrorCode=-2147467259 Number=1064 StackTrace:
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at CaseFinder.Form1.button1_Click(Object sender, EventArgs e) in

CASE is a keyword in MySQL. CASE是MySQL中的关键字。 Try to wrap it with backticks (`) if you meant to select from a table named "case", for example : 如果要从名为“ case”的表中进行选择,请尝试用反引号(`)进行包装,例如:

String searchString = "SELECT * FROM `case`" ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM