Storing Images in SQL using VB.net

Asked By 300 points N/A Posted on -
qa-featured

How to store images in SQl server database using vb.net.I am develop a software that store photo shop images.help me how to do this.

SHARE
Best Answer by Mr.Solution
Best Answer
Best Answer
Answered By 0 points N/A #89182

Storing Images in SQL using VB.net

qa-featured

Hi,

You can store and retrieve  images in sql database using vb.net in form of binary.

Here is the code; I hope it will help you:

Private Sub UploadedFiles_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles UploadedFiles.DoubleClick
'
Dim drv As DataRowView = CType(UploadedFiles.SelectedItem, DataRowView)
Dim selectedText As String = drv.Row("Name").ToString()
Dim id As Long=-1
'
' the id is stored in text. The structure is: id – FileName.
'
id = Long.Parse(selectedText.Substring(0,selectedText.IndexOf(" – ",0)).Trim())
Dim filename As String=Nothing
Dim up As TransferPictures = New TransferPictures()
Dim result As Byte() = up.DownloadFile(id,filename)
up = Nothing

Try:

Dim ms As MemoryStream = New MemoryStream(result, 0, result.Length)
Dim im As Image = Image.FromStream(ms)
Picture.Image = im
Catch ee As Exception
MessageBox.Show("An error has occured.n" + ee.Message)
End Try
End Sub
End Class

End Namespace

Answered By 300 points N/A #89183

Storing Images in SQL using VB.net

qa-featured

I have  created a form where I want to store all types of images like BMP, .Jpg etc; tell me how to do this.

Answered By 0 points N/A #89184

Storing Images in SQL using VB.net

qa-featured

Hi guys,

Here is the code to store images of all kind; Just create the object of images type like this PNG:

Dim storeImage As Bitmap = New Bitmap(100, 100)

Dim imgStream As New System.IO.MemoryStream
Dim ImgBytes As Byte()

storeImage.Save(imgStream, Imaging.ImageFormat.Png)

ImgBytes = imgStream.ToArray

Just change the format where it is PNG to store other types of images.

Answered By 0 points N/A #89185

Storing Images in SQL using VB.net

qa-featured

Yeah, it's good code for you to try this. Remember one thing: first of all, you have to import this file into your program  "Imports System.IO"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbDrives.Items.Clear()
For Each objDrive As DriveInfo In My.Computer.FileSystem.Drives
If objDrive.IsReady Then
cmbDrives.Items.Add(objDrive.Name)
End If
Next
End Sub

Answered By 300 points N/A #89187

Storing Images in SQL using VB.net

qa-featured

Thanks guys for help

Answered By 0 points N/A #89188

Storing Images in SQL using VB.net

qa-featured

Welcome Mr. It's my pleasure

Login/Register to Answer

Related Questions