gpt4 book ai didi

mysql - 将图像保存到 mysql 数据库时出现无法将类型 'System.Byte[]' 的对象转换为类型 'System.IConvertible' 错误

转载 作者:行者123 更新时间:2023-11-29 18:31:58 24 4
gpt4 key购买 nike

我的代码在将图像保存到 mysql 数据库时遇到问题。有人能帮助我吗?

Sub newstud()
If cbCard.Checked = True Then
card = "COMPLETE"
End If
If cbBirthCert.Checked = True Then
birthcert = "COMPLETE"
End If
If cbForm.Checked = True Then
form = "COMPLETE"
End If
If cbGMoral.Checked = True Then
gmoral = "COMPLETE"
End If

If picStr = vbNullString Then
picImage.Image.Save(".png", Imaging.ImageFormat.Png)
picStr = Application.StartupPath + (".\noimage.png")
End If


IMG = (Nothing)
IMG = Image.FromFile(picStr)

MyStream = New MemoryStream
IMG.Save(MyStream, Imaging.ImageFormat.Png)

Dim con As New MySqlConnection(conStr)
con.Open()
Try
Dim cmd As New MySqlCommand("insert into tbregistration(StudName,StudBday,StudGender,Address,DadName,DadBday,DadOccupation,MomName,MomBday,MomOccupation,Contact,LastSchool,Card,Form137,BirthCertificate,GoodMoral,Image)values('" & txtStudName.Text & "','" & dtpBirthday.Text & "','" & cmbGender.Text & "','" & txtAddress.Text & "','" & txtDadName.Text & "','" & dtpDadBday.Text & "','" & txtDadOccu.Text & "','" & txtMomName.Text & "','" & dtpMomBday.Text & "','" & txtMomOccu.Text & "','" & txtContact.Text & "','" & txtLastSchool.Text & "','" & card & "','" & form & "','" & birthcert & "','" & gmoral & "',@img,'"")", con)
cmd.Parameters.AddWithValue("@img", MySqlDbType.VarBinary).Value = MyStream.GetBuffer
cmd.ExecuteNonQuery()
cmd.Dispose()

MyStream.Dispose()
MyStream = Nothing
MsgBox("Admission done successfully", , "Admission")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

这是我的保存按钮的代码

Dim imgdlg As FileDialog = New OpenFileDialog()
imgdlg.Filter = "Image File (*.jpg;*.bmp;*.gif;*.png)|*.jpg;*.bmp;*.gif;*.png"


If imgdlg.ShowDialog() = DialogResult.OK Then
picStr = imgdlg.FileName
Else
picStr = ""
Exit Sub

End If

picImage.Image = Drawing.Image.FromFile(picStr)

这是浏览图像按钮。请帮我。非常感谢

最佳答案

您的意思是写:

Dim cmd As New MySqlCommand("insert into tbregistration(StudName,StudBday,StudGender,Address,DadName,DadBday,DadOccupation,MomName,MomBday,MomOccupation,Contact,LastSchool,Card,Form137,BirthCertificate,GoodMoral,Image)values('" & txtStudName.Text & "','" & dtpBirthday.Text & "','" & cmbGender.Text & "','" & txtAddress.Text & "','" & txtDadName.Text & "','" & dtpDadBday.Text & "','" & txtDadOccu.Text & "','" & txtMomName.Text & "','" & dtpMomBday.Text & "','" & txtMomOccu.Text & "','" & txtContact.Text & "','" & txtLastSchool.Text & "','" & card & "','" & form & "','" & birthcert & "','" & gmoral & "',@img,'"")", con)
cmd.Parameters.AddWithValue("@img", SqlDbType.VarBinary).Value = MyStream.GetBuffer
cmd.ExecuteNonQuery()

请注意第 2 行从 MySqlDbTypeSqlDbType 的更改

关于mysql - 将图像保存到 mysql 数据库时出现无法将类型 'System.Byte[]' 的对象转换为类型 'System.IConvertible' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45605245/

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