gpt4 book ai didi

MySQL INSERT 导致 .ExecuteNonQuery 上的 MySqlException

转载 作者:行者123 更新时间:2023-11-30 00:13:27 25 4
gpt4 key购买 nike

我能够很好地连接到数据库,但是当我尝试 INSERT 时,我收到了这个神秘的错误:

发生错误 0:命令执行期间遇到 fatal error 。

我已经检查过,所有参数都有值,并且它们与列标题完全匹配,除了自动递增的 ID 之外。

请问我哪里出错了?

Dim iReturn As Boolean

Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand

Dim strConnection = "server=" & txtServer.Text & ";" _
& "user id=" & txtUsername.Text & ";" _
& "password=" & txtPassword.Text & ";" _
& "database=" & txtDatabase.Text

conn.ConnectionString = strConnection

Try
conn.Open()
cmd.Connection = conn

cmd.CommandText = "INSERT INTO twc_data VALUES(@todaysdate,@fname,@mname,@lname,@address,@city,@state,@zip,@email,@arPhone(0),@arPhone(1),@arPhone(2),@arCategory(0),@arCategory(1),@arJob1(1),@arJob1(2),@arJob1(3),@arJob1(4),@arJob1(5),@arJob2(1),@arJob2(2),@arJob2(3),@arJob2(4),@arJob2(5),@arJob3(1),@arJob3(2),@arJob3(3),@arJob3(4),@arJob3(5),@arCategory(2),@arCategory(3),@arCategory(4),@arCategory(5),@arCategory(6),@arCategory(7),@arCategory(8),@arCategory(9),@arCategory(10),@pdfilename,@strText)"

cmd.Prepare()

With cmd
.Prepare()
.Parameters.AddWithValue("@todaysdate", param(0))
.Parameters.AddWithValue("@fname", param(1))
.Parameters.AddWithValue("@mname", param(2))
.Parameters.AddWithValue("@lname", param(3))
.Parameters.AddWithValue("@address", param(4))
.Parameters.AddWithValue("@city", param(5))
.Parameters.AddWithValue("@state", param(6))
.Parameters.AddWithValue("@zip", param(7))
.Parameters.AddWithValue("@email", param(8))
.Parameters.AddWithValue("@arPhone(0)", param(9))
.Parameters.AddWithValue("@arPhone(1)", param(10))
.Parameters.AddWithValue("@arPhone(2)", param(11))
.Parameters.AddWithValue("@arCategory(0)", param(12))
.Parameters.AddWithValue("@arCategory(1)", param(13))
.Parameters.AddWithValue("@arJob1(1)", param(14))
.Parameters.AddWithValue("@arJob1(2)", param(15))
.Parameters.AddWithValue("@arJob1(3)", param(16))
.Parameters.AddWithValue("@arJob1(4)", param(17))
.Parameters.AddWithValue("@arJob1(5)", param(18))
.Parameters.AddWithValue("@arJob2(1)", param(19))
.Parameters.AddWithValue("@arJob2(2)", param(20))
.Parameters.AddWithValue("@arJob2(3)", param(21))
.Parameters.AddWithValue("@arJob2(4)", param(22))
.Parameters.AddWithValue("@arJob2(5)", param(23))
.Parameters.AddWithValue("@arJob3(1)", param(24))
.Parameters.AddWithValue("@arJob3(2)", param(25))
.Parameters.AddWithValue("@arJob3(3)", param(26))
.Parameters.AddWithValue("@arJob3(4)", param(27))
.Parameters.AddWithValue("@arJob3(5)", param(28))
.Parameters.AddWithValue("@arCategory(2)", param(29))
.Parameters.AddWithValue("@arCategory(3)", param(30))
.Parameters.AddWithValue("@arCategory(4)", param(31))
.Parameters.AddWithValue("@arCategory(5)", param(32))
.Parameters.AddWithValue("@arCategory(6)", param(33))
.Parameters.AddWithValue("@arCategory(7)", param(34))
.Parameters.AddWithValue("@arCategory(8)", param(35))
.Parameters.AddWithValue("@arCategory(9)", param(36))
.Parameters.AddWithValue("@arCategory(10)", param(37))
.Parameters.AddWithValue("@pdfilename", param(38))
.Parameters.AddWithValue("@strText)", param(39))
End With

cmd.ExecuteNonQuery()
iReturn = True
Catch ex As MySqlException
param(40) = "Error " & ex.Number & " has occurred: " & ex.Message
logError()
iReturn = False
Finally
conn.Close()
End Try

Return iReturn

最佳答案

您应该指定不带 ID 的表的列名。

INSERT INTO twc_data([column names of the table]) VALUES(@todaysdate,.....

关于MySQL INSERT 导致 .ExecuteNonQuery 上的 MySqlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23859783/

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