Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Adding Image in SQL database through vb.net application?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-02-2009
Member
 
Join Date: Jan 2009
Posts: 19
Adding Image in SQL database through vb.net application?
  

Hi,
I want to know How can I add image to the SQL database through the form in my Vb.Net project.

Can you guys please help me with the same?

Regards,

Reply With Quote
  #2  
Old 16-02-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Adding Image in SQL database through vb.net application?

This source code is use to insert picture to SQL Server to binary format that is make the database....

Code:
Function SaveImage _
   (ByVal FileName As String) As Integer

   ' Create a FileInfo instance
   ' to retrieve the files information
   Dim fi As New FileInfo(FileName)

   ' Open the Image file for Read
   Dim imgStream As Stream = _
      fi.OpenRead

   ' Create a Byte array the size
   ' of the image file for the Read
   ' methods buffer() byte array
   Dim imgData(imgStream.Length) As Byte
   imgStream.Read(imgData, 0, fi.Length)

   Dim cn As New SqlConnection _
      (ConfigurationSettings.AppSettings("cn"))
   Dim cmd As New SqlCommand("Images_ins", cn)
   cmd.CommandType = CommandType.StoredProcedure

   With cmd.Parameters
      .Add("@FileName", VarChar, 100).Value = _
         fi.Name
      .Add("@FileType", VarChar, 10).Value = +
         fi.Extension
      .Add("@Image", Image).Value = imgData
      .Add("@FileSize", Int, 4).Value = fi.Length
   End With

   cn.Open()
   cmd.ExecuteNonQuery()
   cn.Close()
   cn.Dispose()
End Function
Reply With Quote
  #3  
Old 16-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,000
Re: Adding Image in SQL database through vb.net application?

See the following links. Hope it will help u.

http://www.codeproject.com/KB/web-image/PicManager.aspx

http://www.vbdotnetheaven.com/Upload...SqlServer.aspx
Reply With Quote
  #4  
Old 16-02-2009
Member
 
Join Date: May 2008
Posts: 40
Re: Adding Image in SQL database through vb.net application?

ASP.NET/VB.NET Code to insert images in MS SQL Server Database.

Follow this link!

http://www.dotnetjunkies.com/WebLog/...les/39751.aspx
Reply With Quote
  #5  
Old 16-02-2009
Member
 
Join Date: May 2008
Posts: 115
Re: Adding Image in SQL database through vb.net application?

Here is the code to insert images to a Ms Access database!

Code:
File name is Image.vb
Imports System
Imports System.IO
Imports System.Data
Public Class SaveImage
Shared Sub main()
Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String
Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine
If Dir(gifFile) = "" Then
   Console.Write("Invalid File Path")
   Exit Sub
End If
o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)
Try
Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data 
Source=Test.mdb")
Dim Sql As String = "INSERT INTO Images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
End Class
A file will be inserted in the Database each time the code is executed.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Adding Image in SQL database through vb.net application?"
Thread Thread Starter Forum Replies Last Post
Nokia C3-01 is not showing contact image after adding in favorites chuck28 Portable Devices 4 04-09-2011 04:02 AM
Warning message when adding data to database Jagavi Software Development 5 28-01-2010 04:40 PM
Problem regarding the adding my thumbnail image to file reetus Windows Software 4 14-12-2009 05:23 PM
How to refresh database after adding a new record? ArunJ Software Development 5 16-02-2009 07:27 PM
Insert image in access database from vb 6.0 Vireshh Software Development 2 22-01-2009 09:06 PM


All times are GMT +5.5. The time now is 12:40 AM.