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



Insert image in access database from vb 6.0

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-01-2009
Member
 
Join Date: Dec 2008
Posts: 12
Insert image in access database from vb 6.0
  

I want to insert image into access database from visualbasic.
When I store image path as text into database it works for me but, I want to save image directly to database.
How can I do this ?

Reply With Quote
  #2  
Old 22-01-2009
Member
 
Join Date: May 2008
Posts: 2,286
Re: Insert image in access database from vb 6.0

This code is to insert the image in the database.

Code:
Dim theFS As New FileStream(Application.StartupPath & "\testImage.JPG", FileMode.Open)
Dim theBytes(theFS.Length) As Byte theFS.Read(theBytes, 0, theBytes.Length)
theFS.Close() 
 
Dim theQuery As New OleDbCommand("INSERT INTO Table1([image]) VALUES(?)", new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1.mdb;User Id=admin;Password=;"))
Dim p1 As New OleDbParameter("@p1", OleDbType.Binary)
p1.Value = theBytes
theQuery.Parameters.Add(p1)
theQuery.Connection.Open()
theQuery.ExecuteNonQuery()
theQuery.Connection.Close()
Reply With Quote
  #3  
Old 22-01-2009
Member
 
Join Date: May 2008
Posts: 2,286
Re: Insert image in access database from vb 6.0

This code is to Read the image from the database.

Code:
Dim theQuery As New OleDbCommand("SELECT ([image]) FROM Table1", New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1.mdb;User Id=admin;Password=;")) Dim theDataSet As New DataSet()
Dim theDataAdapter As New OleDbDataAdapter(theQuery)
 
theQuery.Connection.Open()
theDataAdapter.Fill(theDataSet)
theQuery.Connection.Close()
 
'get row Dim theItem As Object = theDataSet.Tables(0).Rows(0).Item(0)
Dim correctObject() As Byte = CType(theItem, Byte())
If correctObject Is Nothing = False Then    'read into memstream
   Using theMemStream As New MemoryStream()       theMemStream.Write(correctObject, 0, correctObject.Length)
      theMemStream.Position = 0
      Me.PictureBox1.Image = Image.FromStream(theMemStream)
   End Using
End If
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Insert image in access database from vb 6.0"
Thread Thread Starter Forum Replies Last Post
Displaying an Image In a JSP With a Access database Henryosa Software Development 5 12-03-2010 02:52 PM
insert into select statement for database Aidan 12 Software Development 5 09-03-2010 09:08 PM
Is it possible to insert value of TextBox into Sql database using C sharp? Sarfaraj Khan Software Development 5 05-01-2010 10:58 AM
Insert DataGridview into database Neil'o Software Development 3 24-09-2009 11:28 AM
Scan image into an Access database Okies Windows Software 2 22-05-2009 01:37 PM


All times are GMT +5.5. The time now is 11:19 AM.