gpt4 book ai didi

mysql - 使用 VB.net 和 Mysql 服务器的第 1 行出现 Sql 语法错误

转载 作者:行者123 更新时间:2023-11-29 21:51:07 24 4
gpt4 key购买 nike

我收到一个 Sql 语法错误,请检查与您的 MySQL 服务器版本相对应的手册,以了解第 1 行附近用户的正确语法。我正在尝试保存到我的数据库。我正在使用 VB.net。

Imports MySql.Data.MySqlClient
Public Class AddStudent
Dim mydbcon As MySqlConnection
Dim COMMAND As MySqlCommand
Dim da As New MySqlDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
mydbcon = New MySqlConnection
mydbcon.ConnectionString = "server=localhost;userid=jared;password=jared;database=database"
Dim reader As MySqlDataReader
Try
mydbcon.Open()
Dim Query As String
Query = "Insert into database.scitech (Name,Surname,Number,College,Course,Year) values ('" & TextBox1name.Text & "','" & TextBox2su.Text & "','" & TextBox3num.Text & "'"
COMMAND = New MySqlCommand(Query, mydbcon)
reader = COMMAND.ExecuteReader

MessageBox.Show("Data Saved")
mydbcon.Close()

Catch ex As MySqlException
MessageBox.Show(ex.Message)

Finally
mydbcon.Dispose()
End Try

End Sub
End Class

最佳答案

用文字替换变量似乎缺少右括号:

"Insert into database.scitech (Name,Surname,Number,College,Course,Year) values ('abc','def','ghi'"

在调试 SQL 时输出查询可能是个好主意。

关于mysql - 使用 VB.net 和 Mysql 服务器的第 1 行出现 Sql 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com