Image store in database without providing load on database
In this article,I will explain you to store images for any VB.NET Project.
This is an easy method to store images in database, because in most of the projects the whole images are store in table field (MS SQL Server), but this can be done by copying that image in some folder and storing a path of it.
Image storing in database with easy method
The code snippet related to this article is posted below:-
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "Image Files (*.jpg) | *.jpg"
OpenFileDialog1.InitialDirectory = "D:\"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox2.Text = OpenFileDialog1.FileName
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim source As String
Dim dest As String
source = TextBox2.Text
dest = CurDir() & "\img"
FileCopy(source, dest & "\" & TextBox1.Text & ".jpg")
executequery("insert into [check] values(" & TextBox1.Text & ",'" & dest & "\" & TextBox1.Text & ".jpg" & "')")
MsgBox("done")
End Sub
End Class
Thanks,
Dhiraj