在''第1行visual c#附近的MySQL INSERT语法错误

时间:2022-06-01 17:04:55

Im having a hard time solving this error about MySQL Syntax.

我很难解决关于MySQL语法的这个错误。

Here is the MySQL syntax

这是MySQL语法

try
        {
            SQL = "INSERT INTO payment_history_tbl (id, payment_type, date, time, amount, student_no) VALUES (NULL, '" + cmbbxPaymentType.Text + "', CURRENT_DATE(), CURRENT_TIME(), '" + txtbxPaymentAmt.Text + "', '" + msktxbxStudNo.Text + "'";
            // INSERT INTO `studentpaymentqueuing`.`payment_history_tbl` (`id`, `payment_type`, `date`, `time`, `amount`, `student_no`) VALUES (NULL, 'Certificate of Enrollment', '2017-02-24', '10:19:28', '60.00', '13-0695');
            cmd = new MySqlCommand(SQL, conn);
            conn.Open();
            cmd.ExecuteNonQuery();

            conn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

Error 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 '' at line 1

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的''附近使用正确的语法

Any idea?

任何想法?

2 个解决方案

#1


0  

Did you miss )?

你想念吗 )?

SQL = "INSERT INTO payment_history_tbl (id, payment_type, date, time, amount, student_no) VALUES (NULL, '" + cmbbxPaymentType.Text + "', CURRENT_DATE(), CURRENT_TIME(), '" + msktxbxStudNo.Text + "')";

#2


0  

Using String.Format may help you to get pretty code and finding bug easily.
Example:

使用String.Format可以帮助您轻松获得漂亮的代码并发现错误。例:


String query = String.Empty;
query += String.Format("INSERT INTO payment_history_tbl (id, payment_type, date, time, amount, student_no)");
query += String.Format(" VALUES (NULL, '{0}', '{1}', {2}, '{3}', '{4}');", cmbbxPaymentType.Text, CURRENT_DATE(), CURRENT_TIME(), txtbxPaymentAmt.Text, msktxbxStudNo.Text);

#1


0  

Did you miss )?

你想念吗 )?

SQL = "INSERT INTO payment_history_tbl (id, payment_type, date, time, amount, student_no) VALUES (NULL, '" + cmbbxPaymentType.Text + "', CURRENT_DATE(), CURRENT_TIME(), '" + msktxbxStudNo.Text + "')";

#2


0  

Using String.Format may help you to get pretty code and finding bug easily.
Example:

使用String.Format可以帮助您轻松获得漂亮的代码并发现错误。例:


String query = String.Empty;
query += String.Format("INSERT INTO payment_history_tbl (id, payment_type, date, time, amount, student_no)");
query += String.Format(" VALUES (NULL, '{0}', '{1}', {2}, '{3}', '{4}');", cmbbxPaymentType.Text, CURRENT_DATE(), CURRENT_TIME(), txtbxPaymentAmt.Text, msktxbxStudNo.Text);