|
-
May 12th, 2009, 07:29 AM
#1
Thread Starter
New Member
saving images to database
Hi,
This is a newbie question. I am trying to create an applicatiojn which allows the user to enter info on plants including photos. I have set up the database using image datatype and created the form using the dataset but when I save the data everything is saved but the image file. Obviously I need extra code but I can't find anything in the help files etc that shows me. This is the code I have at the moment
Imports System.IO
Public Class NewTree
Dim openFileDialog1 As New OpenFileDialog()
Dim fileName As String
Private Sub TreesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TreesBindingNavigatorSaveItem.Click
Me.Validate()
Me.TreesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.LibraryDataSet)
End Sub
Private Sub NewTree_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LibraryDataSet.Trees' table. You can move, or remove it, as needed.
'Me.TreesTableAdapter.Fill(Me.LibraryDataSet.Trees)
End Sub
'Browse for image to be stored in data base
Private Sub ImageBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageBtn.Click
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
Dim fileName As String
With openFileDialog1
.InitialDirectory = "C:\" 'set initial drive for browsing
.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
.FilterIndex = 4 'set first type of files
End With
Try
If openFileDialog1.ShowDialog() = DialogResult.OK Then 'opens dialog box
fileName = openFileDialog1.FileName 'gets file name
With ImagePictureBox
.Image = Image.FromFile(fileName) 'sets image into picture box
.SizeMode = PictureBoxSizeMode.StretchImage 'sets image size
End With
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Sub
Please if any one can help me -
-
May 12th, 2009, 07:49 AM
#2
Re: saving images to database
Follow the CodeBank link in my signature and you'll find my submission on the subject.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|