Vb.net使用mysql数据库将图像更新到数据库 [英] Vb.net Updating Image to Datase using mysql Database
问题描述
大家好,我有更新信息的问题,我使用的是mysql数据库,问题是当用户更新信息列表时,例如客户,用户想尝试更改客户的图片,这样他/她需要更新到数据库,当我尝试更新一些更改,主要是图像没有变化,我有错误,当我点击客户列表它说:无效的参数和后来的东西弹出它说:致命错误需要关闭...我不知道它为什么会发生但我的目标是实现客户信息的一些变化,主要目标是图片..
以下是代码:
Hello Everyone, i have a problem in updating information, i am using mysql database, the problem is when user is updating the list of information , for example customer, user wants to try change the picture of their customer so he / she needs to update it into database, when i try to update some changes and mainly the image was not changes, i have error when i click to the customer list it say : Invalid Paramater and later something pop-up it says:Fatal Error need to close... i don't know the reason why it happen but my objective is to achieve the some changes of customer information which is the main target is the picture..
Here is the code:
Try
Dim conn As MySqlConnection
conn = New MySqlConnection()
conn.ConnectionString = "server=localhost; user id=root; password=zhakige; database=Barangay_170_2"
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM Residents WHERE ID= '" + lblID.Text + "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdapter.SelectCommand = myCommand
conn.Close()
conn.Open()
Dim ms As New MemoryStream
Dim bm As Bitmap = New Bitmap(PictureBox2.Image)
bm.Save(ms, PictureBox2.Image.RawFormat)
Dim arrPic() As Byte = ms.GetBuffer()
sqlquery = "update Residents set Image=@Image where ID=@ID"
myCommand = New MySqlCommand(sqlquery, conn)
myCommand.Parameters.AddWithValue("@Image", arrPic)
myCommand.ExecuteNonQuery()
conn.Close()
myAdapter.Fill(ds)
list()
Catch ex As MySqlException
MessageBoxEx.Show(ex.Message)
End Try
我希望有人通过将图像更新到mysql数据库来改变客户图像。
我向你们致以诚挚的问候,
Nathan - 我的真实姓名
I hope someone done this by updating images to mysql database to changes the customer images.
My Warm Regards to you all,
Nathan - it my real name
推荐答案
用于执行更新的 sqlquery
有两个参数。 @Image和@ID。但你只是设置@Image。也设置@ID。
The sqlquery
that you are using to do the update has two parameters. @Image and @ID. But you are only setting @Image. Set @ID too.
这篇关于Vb.net使用mysql数据库将图像更新到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!