Hello All,
I have been fighting this for DAYS now, I have a picturebox that I place an .png image in, I then have an Update button to add this image to a Database.
I have tried severl tutorials on adding images to a database all with the same results.
There is no exception throwen or error of any kind, but when I open the database it is empty.
Here is the code I got from Microsofts Web Site last and tried. I was article number 317670 here is the code I have.
I tried changing it from varbinary to image on the sqldbtype with same results.
I load the image in the picturebox, click the button, and then look at the table, which is still empty.
Any help would be greatly appreciated, and by the way, I know people say it is BAD practice to store images in a databse, just store a path, but I do NOT want 1800 images in a directory when my clients use my program.
Thanks in advance.
Ferlin.
I have been fighting this for DAYS now, I have a picturebox that I place an .png image in, I then have an Update button to add this image to a Database.
I have tried severl tutorials on adding images to a database all with the same results.
There is no exception throwen or error of any kind, but when I open the database it is empty.
Here is the code I got from Microsofts Web Site last and tried. I was article number 317670 here is the code I have.
Code:
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
If Trim(txtImageName.Text) = "" Then
MsgBox("Please Select An Image.")
Exit Sub
End If
Dim cn As New SqlConnection(strCon)
Dim cmd As New SqlCommand("INSERT INTO Images ([ImageName], [ImageData]) VALUES (@ImageName, @ImageData)", cn)
Dim ms As MemoryStream = New MemoryStream()
pbIconImage.Image.Save(ms, ImageFormat.Jpeg)
Dim bytIconData(ms.Length - 1) As Byte
ms.Position = 0
ms.Read(bytIconData, 0, ms.Length)
ms.Close()
Dim prmName As New SqlParameter("@ImageName", SqlDbType.NVarChar, 50, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, Trim(lblIconName.Text))
Dim prmImage As New SqlParameter("@ImageData", SqlDbType.Image, bytIconData.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, bytIconData)
cmd.Parameters.Add(prmName)
cmd.Parameters.Add(prmImage)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
End Sub
I tried changing it from varbinary to image on the sqldbtype with same results.
I load the image in the picturebox, click the button, and then look at the table, which is still empty.
Any help would be greatly appreciated, and by the way, I know people say it is BAD practice to store images in a databse, just store a path, but I do NOT want 1800 images in a directory when my clients use my program.
Thanks in advance.
Ferlin.