|
| ||||||||||
| Tags: image in access, image in databse, insert image, vb image |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| Insert image in access database from vb 6.0
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 ? |
|
#2
| ||||
| ||||
| 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() |
|
#3
| ||||
| ||||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |