473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to insert binary image into MS-Access using.net

I have a source database which stores the main image.
I read the image out as this :

Dim strSQL As String
Dim objData As clsDatabase
Dim dr As OleDb.OleDbDataReader

strSQL += "select * from picstable" ' this is a foxpro database
'open object for database work
objData = objData.GetInstance

dr = objData.GetDatareader(strSQL)
While dr.Read
objWriter.Write(dr.Item("picdata"))
end while

So now i have the data i need to copy it into another (Ms-Access)
database..

I tried this..
While dr.Read

strConnStr = ConfigurationSettings.AppSettings("connString")
Dim objConn As New OleDbConnection(strConnStr)
objConn.Open()

Dim cmd As New OleDbCommand("INSERT INTO prodpics(pic) VALUES (?)",
objConn)
Dim bytearray() As Byte

cmd.Parameters.Add(dr.Item("picdata"), OleDbType.Binary).Value =
bytearray

objConn.Open()
cmd.ExecuteNonQuery()
objConn.Close()
end while

I get a huge error message, im new to paramterised queries such as this
so any help appreciated
error is :

System.Reflection.AmbiguousMatchException: No accessible overloaded
'OleDbParameterCollection.Add' can be called without a narrowing
conversion. at
Microsoft.VisualBasic.CompilerServices.VBBinder.se t_InternalThrow(Exception
Value) at
Microsoft.VisualBasic.CompilerServices.VBBinder.Bi ndToMethod(BindingFlags
bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[]
modifiers, CultureInfo culture, String[] names, Object& ObjState) at
Microsoft.VisualBasic.CompilerServices.VBBinder.In vokeMember(String
name, BindingFlags invokeAttr, Type objType, IReflect objIReflect,
Object target, Object[] args, ParameterModifier[] modifiers,
CultureInfo culture, String[] namedParameters) at
Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack) at eXcommerce.WebForm1.Button2_Click(Object sender,
EventArgs e) in www...

Nov 19 '05 #1
6 4900
On 13 Jul 2005 07:07:51 -0700, "androoo" <an***********@hotmail.com>
wrote:

<snip>

Have you looked at Cor's example on this subject:

http://groups-beta.google.com/group/...9590856?hl=en&

Or

http://groups.google.co.uk/group/mic...5e5a89b895f812

Hope this helps

Tom
Nov 19 '05 #2
On 13 Jul 2005 07:07:51 -0700, "androoo" <an***********@hotmail.com> wrote:

¤ I have a source database which stores the main image.
¤ I read the image out as this :
¤
¤ Dim strSQL As String
¤ Dim objData As clsDatabase
¤ Dim dr As OleDb.OleDbDataReader
¤
¤ strSQL += "select * from picstable" ' this is a foxpro database
¤ 'open object for database work
¤ objData = objData.GetInstance
¤
¤ dr = objData.GetDatareader(strSQL)
¤ While dr.Read
¤ objWriter.Write(dr.Item("picdata"))
¤ end while
¤
¤ So now i have the data i need to copy it into another (Ms-Access)
¤ database..
¤
¤ I tried this..
¤ While dr.Read
¤
¤ strConnStr = ConfigurationSettings.AppSettings("connString")
¤ Dim objConn As New OleDbConnection(strConnStr)
¤ objConn.Open()
¤
¤ Dim cmd As New OleDbCommand("INSERT INTO prodpics(pic) VALUES (?)",
¤ objConn)
¤ Dim bytearray() As Byte
¤
¤ cmd.Parameters.Add(dr.Item("picdata"), OleDbType.Binary).Value =
¤ bytearray
¤
¤ objConn.Open()
¤ cmd.ExecuteNonQuery()
¤ objConn.Close()
¤ end while
¤
¤ I get a huge error message, im new to paramterised queries such as this
¤ so any help appreciated
¤ error is :
¤
¤ System.Reflection.AmbiguousMatchException: No accessible overloaded
¤ 'OleDbParameterCollection.Add' can be called without a narrowing
¤ conversion. at
¤ Microsoft.VisualBasic.CompilerServices.VBBinder.se t_InternalThrow(Exception
¤ Value) at
¤ Microsoft.VisualBasic.CompilerServices.VBBinder.Bi ndToMethod(BindingFlags
¤ bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[]
¤ modifiers, CultureInfo culture, String[] names, Object& ObjState) at
¤ Microsoft.VisualBasic.CompilerServices.VBBinder.In vokeMember(String
¤ name, BindingFlags invokeAttr, Type objType, IReflect objIReflect,
¤ Object target, Object[] args, ParameterModifier[] modifiers,
¤ CultureInfo culture, String[] namedParameters) at
¤ Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o,
¤ Type objType, String name, Object[] args, String[] paramnames,
¤ Boolean[] CopyBack) at eXcommerce.WebForm1.Button2_Click(Object sender,
¤ EventArgs e) in www...

You should be able to adapt the following to your code:

Sub WriteBlobToAccess()

Dim SourceFilePath As String
SourceFilePath = "e:\My Documents\Greenstone.bmp"
Dim AccessConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=e:\My Documents\db1.mdb")
Dim AccessCommand As New OleDbCommand("UPDATE Table1 SET OLEField=? WHERE [record id] = 1",
AccessConnection)
Dim FileStreamObject As New System.IO.FileStream(SourceFilePath, IO.FileMode.Open,
IO.FileAccess.Read)
Console.Write(FileStreamObject.Length)
Dim PictureByteArray(CType(FileStreamObject.Length() - 1, Integer)) As Byte
FileStreamObject.Read(PictureByteArray, 0, PictureByteArray.Length)
FileStreamObject.Close()
Dim QueryParameter As New OleDbParameter("@Picture", OleDbType.LongVarBinary,
PictureByteArray.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current,
PictureByteArray)
AccessCommand.Parameters.Add(QueryParameter)
AccessConnection.Open()
AccessCommand.ExecuteNonQuery()
AccessConnection.Close()

End Sub
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #3
Thanks for all the help so far, im getting more success with reading
out from different databases with your examples but writing into access
is still causing some problems.
I followed your examples and adapted the code to this to insert a image
into access.

While dr.Read

objWriter.Write(dr.Item("picdata"))
bmpFile = New Bitmap(stmFile)
stmFile.Read(byt, 0, byt.Length)

strConnStr =
ConfigurationSettings.AppSettings("connString")
Dim objConn As New OleDbConnection(strConnStr)
objConn.Open()

Dim DBCmd As New OleDb.OleDbCommand("UPDATE exproduct
SET pic=@pic WHERE id = 1207", objConn)
Dim P As New OleDb.OleDbParameter("@pic",
OleDb.OleDbType.LongVarBinary, byt.Length, ParameterDirection.Input,
False, 0, 0, Nothing, DataRowVersion.Current, byt)
DBCmd.Parameters.Add(P)
DBCmd.ExecuteNonQuery()
stmFile.Close()
End While

The code runs through and doesnt fail and gives the impression its
working, however there is nothing added to the database... can you see
anything obvious im doing wrong, im a little out of my depth with this
!

Thanks again!

Nov 19 '05 #4
On 14 Jul 2005 07:35:11 -0700, "androoo" <an***********@hotmail.com> wrote:

¤ Thanks for all the help so far, im getting more success with reading
¤ out from different databases with your examples but writing into access
¤ is still causing some problems.
¤ I followed your examples and adapted the code to this to insert a image
¤ into access.
¤
¤ While dr.Read
¤
¤ objWriter.Write(dr.Item("picdata"))
¤ bmpFile = New Bitmap(stmFile)
¤ stmFile.Read(byt, 0, byt.Length)
¤
¤ strConnStr =
¤ ConfigurationSettings.AppSettings("connString")
¤ Dim objConn As New OleDbConnection(strConnStr)
¤ objConn.Open()
¤
¤ Dim DBCmd As New OleDb.OleDbCommand("UPDATE exproduct
¤ SET pic=@pic WHERE id = 1207", objConn)
¤ Dim P As New OleDb.OleDbParameter("@pic",
¤ OleDb.OleDbType.LongVarBinary, byt.Length, ParameterDirection.Input,
¤ False, 0, 0, Nothing, DataRowVersion.Current, byt)
¤ DBCmd.Parameters.Add(P)
¤ DBCmd.ExecuteNonQuery()
¤ stmFile.Close()
¤ End While
¤
¤ The code runs through and doesnt fail and gives the impression its
¤ working, however there is nothing added to the database... can you see
¤ anything obvious im doing wrong, im a little out of my depth with this
¤ !

How have you verified that nothing has been written to the database? What is the data type you are
using to store the binary image?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #5
I am using an OLEObject type.
I tested by adding an image in manually and testing the code that reads
the image.
When I insert manually the code returns the image. When I insert with
the the above code it is empty,,,, is there anything abvious you can
see wrong with the code ?

Thanks for your help

Nov 19 '05 #6
On 14 Jul 2005 12:35:38 -0700, "androoo" <an***********@hotmail.com> wrote:

¤ I am using an OLEObject type.
¤ I tested by adding an image in manually and testing the code that reads
¤ the image.
¤ When I insert manually the code returns the image. When I insert with
¤ the the above code it is empty,,,, is there anything abvious you can
¤ see wrong with the code ?

What if you use the example I posted to read it in from a file? Does that code work?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PearCZ | last post by:
Hi, I am trying to store binary data (e. g. image) in MS SQL Server 2000 column which data type is . I understand I could store binary data easily in MS SQL type but I have only column...
2
by: S.Creek | last post by:
Hi, I need to take few files (images in my case) and create one file out of them, this file should be accessed so i can grab a single image from it if necessary, i thought of taking all the...
2
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
4
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
8
by: gsmith | last post by:
Hello, I am developing a video recording (mjpeg) system which records large binary files. I need to read the JPEG data from the binary file and create a bitmap object to be displayed....
11
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
3
by: jenp | last post by:
Hello I've got a rather tricky problem here - i'm looking to insert a graph into a web page - which is represented as a jpeg image. Due to the restrictions of the framework i'm developing...
2
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
1
by: sandraboy07 | last post by:
Hi, anyone. I have a problem with code php. I have image store in MS SQL Server and now i have a web code with php and i use MS SQL Server as datastore. I want to retrieve my image from DB or...
0
by: getpunith | last post by:
Hi all, How can export or insert an Image to MS WORD 2007. Doc.InlineShapes.AddPicture() needs an Image file stored on disk space, But I dont have Image file.What I have is an Image object. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.