본문 바로가기
MySql

MySQL MySql 구문 오류 : 1 행의 ''근처에 SQL 구문에 오류가 있습니다.

by 베이스 공부 2020. 12. 11.
반응형

수정 : 어리석은 질문에 대해 사과드립니다. 집중력이 부족하고 SQL 구문을 배우고 있다는 사실 때문에 문제를 놓치게되었습니다.

원래 질문 : 여기서 무슨 일이 일어나고 있는지 전혀 모릅니다. 데이터를 삽입하는 여러 가지 방법을 시도했지만 지금까지 아무것도 작동하지 않았으며 항상 동일한 예외가 발생합니다. 문제의 원인이 무엇인지 잘 모르겠습니다. 명령 기능이 누락되었거나 구문에 문제가 있습니까?

string uName = "tess";
string uPwd = "newpassword";
int authorityLevel = 3;

try
{
    mySqlCommand = mySqlConnect.CreateCommand();
    mySqlCommand.CommandText = "INSERT INTO Users(UserName, UserPassword, AuthorityLevel) VALUES(\"" + uName + "\", \"" + uPwd + "\", " + authorityLevel + ";";
    mySqlCommand.ExecuteNonQuery();
}
catch ((MySql.Data.MySqlClient.MySqlException e)
{
    Console.WriteLine(e.Message);
}

// Output:
// 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 '' at line 1

 

해결 방법

 

닫는 꺾쇠 괄호)를 잊어 버렸습니다.

mySqlCommand.CommandText = "INSERT INTO Users(UserName, UserPassword, AuthorityLevel) VALUES(\"" + uName + "\", \"" + uPwd + "\", " + authorityLevel + ";";

이것을 이것으로 바꾸십시오

mySqlCommand.CommandText = "INSERT INTO Users(UserName, UserPassword, AuthorityLevel) VALUES(\"" + uName + "\", \"" + uPwd + "\", " + authorityLevel + ");";

그리고 여는 꺾쇠 괄호를 추가했습니다 (

catch ((MySql.Data.MySqlClient.MySqlException e)

이것을

catch (MySql.Data.MySqlClient.MySqlException e)

 

참조 페이지 https://stackoverflow.com/questions/21474288

 

 

반응형

댓글