hello there am relatively new to vb.net(i am using vb.net 2008 specifically visual studio not c#)
i have been able to save images into an access database but my problem is to be able to retrieve the images from the database(using access 2003)
here is my saving code
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If inc <> -1 Then
Dim cmd As New OleDb.OleDbCommand(sql, con)
Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim breader As New BinaryReader(fsreader)
Dim imgbuffer(fsreader.Length) As Byte
Dim ms As New MemoryStream()
breader.Read(imgbuffer, 0, fsreader.Length)
fsreader.Close()
picPhoto.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
con.Open()
sql = "INSERT INTO CONTACTS(AGENTNUMBER,FIRSTNAME,MIDDLENAME,SURNAME,GENDER,EMAIL,PHONE,ADDRESS,NOTES,PICTURE)"
sql = sql & "VALUES(@AGENTNUMBER,@FIRSTNAME,@MIDDLENAME,@SURNAME,@GENDER,@EMAIL,@PHONE,@ADDRESS,@NOTES,@PICTURE)"
cmd.CommandText = sql
cmd.Connection = con
cmd.Parameters.AddWithValue("@AGENTNUMBER", txtAgentNumber.Text)
cmd.Parameters.AddWithValue("@FIRSTNAME", txtFirstName.Text)
cmd.Parameters.AddWithValue("@MIDDLENAME", txtMiddleName.Text)
cmd.Parameters.AddWithValue("@SURNAME", txtSurName.Text)
cmd.Parameters.AddWithValue("@GENDER", cboGender.Text)
cmd.Parameters.AddWithValue("@EMAIL", txtEmail.Text)
cmd.Parameters.AddWithValue("@PHONE", txtPhone.Text)
cmd.Parameters.AddWithValue("@ADDRESS", txtAddress.Text)
cmd.Parameters.AddWithValue("@NOTES", txtNotes.Text)
cmd.Parameters.AddWithValue("@PICTURE", ms.ToArray())
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("NEW RECORD ADDED")
ds.AcceptChanges()
btnSave.Enabled = False
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
End If
End Sub
here is my code for retrieving the image
Sub retrieve()
Using con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PEOPLE.mdb")
con.Open()
Using cmd As New OleDbCommand("SELECT PICTURE FROM CONTACTS WHERE AGENTNUMBER='" & txtAgentNumber.Text & "'", con)
Dim imageobj = cmd.ExecuteScalar
If Not imageobj Is Nothing AndAlso Not imageobj Is DBNull.Value Then
Using ms As New System.IO.MemoryStream
Dim bm As Bitmap
Dim byteArray = DirectCast(imageobj, Byte())
ms.Write(byteArray, 0, byteArray.Length - 1)
bm = New Bitmap(ms)
picPhoto.Image = bm ---- here is where the problem is ((parameter not valid))
End Using
End If
End Using
End Using
End Sub
i have googled for the solution but i haven't gotten it
i have been stuck here for the past 1 month