Question Store Image in SQL database

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Experts

Table "employees" has four fields as
sno---name---city-----photo
1------a-----london----
2------b----Tehran----
3------c-----dublin----


I use following codes to pickup employees pictures, How to store photos into table "employees" column photo.


VB.NET:
 Dim OpenFileDialog1 As New System.Windows.Forms.OpenFileDialog
        Dim pic As Image
        Dim retVal As DialogResult
        Dim bExOccured As Boolean

        Try
            OpenFileDialog1.Multiselect = False
            'OpenFileDialog1.InitialDirectory = "C:temp"
            OpenFileDialog1.Title = "Please Select a Photo"
            OpenFileDialog1.Filter = "JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|Bmp Files (*.Bmp)|*.bmp"
            retVal = OpenFileDialog1.ShowDialog()
            pic = New Bitmap(OpenFileDialog1.FileName)

            If retVal = Windows.Forms.DialogResult.Cancel Then
                Exit Sub
            End If


            If retVal = Windows.Forms.DialogResult.OK Then
                Label5.Text = OpenFileDialog1.FileName
                PictureBox1.Image = pic

                Dim filePath As String = Label5.Text
                Dim slashPosition As Integer = filePath.LastIndexOf("\")
                Dim filenameOnly As String = filePath.Substring(slashPosition + 1)
                Label5.Text = filenameOnly

            End If
 
Dear Sir,

The images will remain exist on hard disk, I want to only file name in database.

Other method is to store image in database,

Which one is the best??? I do not know

Please help
 
The best method is up to the programmer (in this case, you) to decide...however, the easiest would be the name and full disk path. That is nothing more than a string.
 
Back
Top