gpt4 book ai didi

mysql - 命令文本属性尚未正确初始化

转载 作者:行者123 更新时间:2023-11-29 18:37:12 25 4
gpt4 key购买 nike

当我尝试在 Insert 语句中添加图像时遇到问题。留言内容

The Command Text property has not been properly initialized

出现了。我尝试寻找解决方案,但仍然不知道如何解决。

代码如下:

Public Sub Insertplayer()
dbconn.ConnectionString = "server='" & My.Settings.ip & "';port=3306; user id='" & My.Settings.uid & "';password='" & My.Settings.pwd & "'; database= '" & My.Settings.db & "';"
dbcomm.Connection = dbconn
fname = imageurltxt.Text
Dim Content As Byte() = ImageToStream(fname)
Try
dbconn.Open()
Dim query As String
query = "INSERT INTO `player`(`ID`, `First_Name`, `Last_Name`, `Gender`, `Date_of_Birth`, `Civil_Status`, `Nationality`, `Address`, `Status', `Picture`) VALUES('" + TextBox7.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox9.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "', @Pic)"
dbcomm.Parameters.AddWithValue("@Pic", Content)
dbcomm.ExecuteNonQuery()
dbcomm = New MySqlCommand(query, dbconn)
dbread = dbcomm.ExecuteReader
dbread.Close()

Catch ex As Exception
MsgBox(ex.Message)
Finally
dbconn.Close()
End Try
End Sub
Private Function ImageToStream(ByVal fileName As String) As Byte()
Dim stream As New MemoryStream()
tryagain:
Try
Dim image As New Bitmap(fileName)
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)

Catch ex As Exception
GoTo tryagain
End Try
Return stream.ToArray()
End Function

最佳答案

您正在调用

dbcomm.ExecuteNonQuery()

在以任何方式设置查询之前。此时,您的插入语句仅可用作名为 query 的字符串变量的内容。

不清楚代码示例中变量 dbcomm 来自何处。

关于mysql - 命令文本属性尚未正确初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45194035/

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