EDN Admin
Well-known member
Hi to all,
i would like to seek for your help about my problem with saving image into sql database. Please the code below.
<pre class="prettyprint Private imagetouse As Image
Private mImageFilePath As String
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles UploadBtn.Click
Try
myqry = "INSERT INTO dbo.Student(ProfilePicture) values (@1)"
Using ms As New IO.MemoryStream
imagetouse.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim byteArray = ms.ToArray
mycmd.Parameters.AddWithValue("@1", byteArray)
mycmd.ExecuteNonQuery()
End Using
Catch ex As Exception
MsgBox("not saved!")
End Try
conn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Set Image File"
OpenFileDialog1.Filter = "Bitmap Files|*.bmp" & _
"|Gif Files|*.gif|JPEG Files|*.jpg"
OpenFileDialog1.DefaultExt = "jpg"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
Dim sFilePath As String
sFilePath = OpenFileDialog1.FileName
If sFilePath = "" Then Exit Sub
If System.IO.File.Exists(sFilePath) = False Then
Exit Sub
Else
ProfilePicturePictureBox.ImageLocation = sFilePath
mImageFilePath = sFilePath
End If
End Sub
[/code]
the open dialog box is working fine and im able to choose what ever picture file i want but my problem is i cant save it to sql database. One thing is i put image column in one table together with other columns like firstname, lastname etc. Any help please.
thanks in advance.<br/>
<hr class="sig jocker > im learning
View the full article
i would like to seek for your help about my problem with saving image into sql database. Please the code below.
<pre class="prettyprint Private imagetouse As Image
Private mImageFilePath As String
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles UploadBtn.Click
Try
myqry = "INSERT INTO dbo.Student(ProfilePicture) values (@1)"
Using ms As New IO.MemoryStream
imagetouse.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim byteArray = ms.ToArray
mycmd.Parameters.AddWithValue("@1", byteArray)
mycmd.ExecuteNonQuery()
End Using
Catch ex As Exception
MsgBox("not saved!")
End Try
conn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Set Image File"
OpenFileDialog1.Filter = "Bitmap Files|*.bmp" & _
"|Gif Files|*.gif|JPEG Files|*.jpg"
OpenFileDialog1.DefaultExt = "jpg"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
Dim sFilePath As String
sFilePath = OpenFileDialog1.FileName
If sFilePath = "" Then Exit Sub
If System.IO.File.Exists(sFilePath) = False Then
Exit Sub
Else
ProfilePicturePictureBox.ImageLocation = sFilePath
mImageFilePath = sFilePath
End If
End Sub
[/code]
the open dialog box is working fine and im able to choose what ever picture file i want but my problem is i cant save it to sql database. One thing is i put image column in one table together with other columns like firstname, lastname etc. Any help please.
thanks in advance.<br/>
<hr class="sig jocker > im learning
View the full article