Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
VB
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


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
Posted
Updated 22-Oct-13 8:44am
v2

1 solution

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.
 
Share this answer
 
Comments
tanginamogagoka 23-Oct-13 22:19pm    
I used ID's to identify which field where i can change the image...not to update and change ID , by the way this question is already solved by me.. as u can see it is working code for updating field where image can be change,the cause of the problem is the location of image , i forgot to specify the type of images, well is done and thank for your reply... Nathan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900