I have an Add Form where I can add records to my db with 3 fields (Last Name, First Name and a Picture).
There is no error whatsoever but now I'm stuck on how to EDIT/UPDATE each record's IMAGE.
I can update the First Name and Last Name but I don't how to update the Image. Can someone be nice enough to lead me on the right direction? Perhaps the syntax on my UPDATE table SET field.
Here's my Add Form:
And here's my current Edit Form (without the Picture update)
I tried adding the Picture on the UPDATE syntax but it won't accept it since Picture is not a string. What syntax should I use to update it? Any help would be greatly appreciated. :D
There is no error whatsoever but now I'm stuck on how to EDIT/UPDATE each record's IMAGE.
I can update the First Name and Last Name but I don't how to update the Image. Can someone be nice enough to lead me on the right direction? Perhaps the syntax on my UPDATE table SET field.
Here's my Add Form:
Dim sConnection As MySqlConnection = New MySqlConnection("SERVER = localhost; USERID = root; PASSWORD = loadedro; DATABASE = adbms_test_db;") Dim sCommand As MySqlCommand Dim fStream As FileStream Dim bReader As BinaryReader Try If txt_last_name.Text.Length > 0 And txt_image.Text.Length > 0 Then Dim FileName As String = txt_image.Text Dim ImageData() As Byte fStream = New FileStream(FileName, FileMode.Open, FileAccess.Read) bReader = New BinaryReader(fStream) ImageData = bReader.ReadBytes(CType(fStream.Length, Integer)) bReader.Close() fStream.Close() Dim CmdString As String = "INSERT INTO tbl_adbms_test(LastName, FirstName, Picture) VALUES(@LastName, @FirstName, @Picture)" sCommand = New MySqlCommand(CmdString, sConnection) sCommand.Parameters.Add("@LastName", MySqlDbType.VarChar, 45) sCommand.Parameters.Add("@FirstName", MySqlDbType.VarChar, 45) sCommand.Parameters.Add("@Picture", MySqlDbType.Blob) sCommand.Parameters("@LastName").Value = txt_last_name.Text sCommand.Parameters("@FirstName").Value = txt_first_name.Text sCommand.Parameters("@Picture").Value = ImageData sConnection.Open() Dim RowsAffected As Integer = sCommand.ExecuteNonQuery() If (RowsAffected > 0) Then MsgBox("The record was saved.", MsgBoxStyle.Information) pic_box_stud.Image = Nothing txt_image.Text = "" txt_last_name.Text = "" txt_first_name.Text = "" End If sConnection.Close() Else MsgBox("Incomplete data!", MsgBoxStyle.Critical, "") End If Catch ex As Exception MsgBox(ex.ToString()) Finally If sConnection.State = ConnectionState.Open Then sConnection.Close() End If End Try frm_main.LoadPeople() Close()
And here's my current Edit Form (without the Picture update)
If sConnection.State = ConnectionState.Closed Then sConnection.ConnectionString = "SERVER = localhost; USERID = root; PASSWORD = loadedro; DATABASE = adbms_test_db" sConnection.Open() End If Dim sqlQuery As String = "UPDATE tbl_adbms_test SET LastName='" & txt_last_name.Text & "', FirstName='" & txt_first_name.Text & "' WHERE IDNo='" & IDNo & "'" Dim sqlCommand As New MySqlCommand With sqlCommand .CommandText = sqlQuery .Connection = sConnection .ExecuteNonQuery() End With MsgBox("Record updated successfully.", MsgBoxStyle.Information) Dispose() Close() frm_main.LoadPeople()
I tried adding the Picture on the UPDATE syntax but it won't accept it since Picture is not a string. What syntax should I use to update it? Any help would be greatly appreciated. :D