473,671 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OleDbData Reader

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

dr = objData.GetData reader(strSQL)
While dr.Read
objWriter.Write (dr.Item("picda ta"))
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 = ConfigurationSe ttings.AppSetti ngs("connString ")
Dim objConn As New OleDbConnection (strConnStr)
objConn.Open()

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

cmd.Parameters. Add(dr.Item("pi cdata"), OleDbType.Binar y).Value =
bytearray

objConn.Open()
cmd.ExecuteNonQ uery()
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.Reflecti on.AmbiguousMat chException: No accessible overloaded
'OleDbParameter Collection.Add' can be called without a narrowing
conversion. at
Microsoft.Visua lBasic.Compiler Services.VBBind er.set_Internal Throw(Exception
Value) at
Microsoft.Visua lBasic.Compiler Services.VBBind er.BindToMethod (BindingFlags
bindingAttr, MethodBase[] match, Object[]& args, ParameterModifi er[]
modifiers, CultureInfo culture, String[] names, Object& ObjState) at
Microsoft.Visua lBasic.Compiler Services.VBBind er.InvokeMember (String
name, BindingFlags invokeAttr, Type objType, IReflect objIReflect,
Object target, Object[] args, ParameterModifi er[] modifiers,
CultureInfo culture, String[] namedParameters ) at
Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateGet(O bject o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack) at eXcommerce.WebF orm1.Button2_Cl ick(Object sender,
EventArgs e) in www...

Nov 19 '05 #1
6 4920
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.OleDbData Reader
¤
¤ strSQL += "select * from picstable" ' this is a foxpro database
¤ 'open object for database work
¤ objData = objData.GetInst ance
¤
¤ dr = objData.GetData reader(strSQL)
¤ While dr.Read
¤ objWriter.Write (dr.Item("picda ta"))
¤ 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 = ConfigurationSe ttings.AppSetti ngs("connString ")
¤ Dim objConn As New OleDbConnection (strConnStr)
¤ objConn.Open()
¤
¤ Dim cmd As New OleDbCommand("I NSERT INTO prodpics(pic) VALUES (?)",
¤ objConn)
¤ Dim bytearray() As Byte
¤
¤ cmd.Parameters. Add(dr.Item("pi cdata"), OleDbType.Binar y).Value =
¤ bytearray
¤
¤ objConn.Open()
¤ cmd.ExecuteNonQ uery()
¤ 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.Reflecti on.AmbiguousMat chException: No accessible overloaded
¤ 'OleDbParameter Collection.Add' can be called without a narrowing
¤ conversion. at
¤ Microsoft.Visua lBasic.Compiler Services.VBBind er.set_Internal Throw(Exception
¤ Value) at
¤ Microsoft.Visua lBasic.Compiler Services.VBBind er.BindToMethod (BindingFlags
¤ bindingAttr, MethodBase[] match, Object[]& args, ParameterModifi er[]
¤ modifiers, CultureInfo culture, String[] names, Object& ObjState) at
¤ Microsoft.Visua lBasic.Compiler Services.VBBind er.InvokeMember (String
¤ name, BindingFlags invokeAttr, Type objType, IReflect objIReflect,
¤ Object target, Object[] args, ParameterModifi er[] modifiers,
¤ CultureInfo culture, String[] namedParameters ) at
¤ Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateGet(O bject o,
¤ Type objType, String name, Object[] args, String[] paramnames,
¤ Boolean[] CopyBack) at eXcommerce.WebF orm1.Button2_Cl ick(Object sender,
¤ EventArgs e) in www...

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

Sub WriteBlobToAcce ss()

Dim SourceFilePath As String
SourceFilePath = "e:\My Documents\Green stone.bmp"
Dim AccessConnectio n As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;" & _
"Data Source=e:\My Documents\db1.m db")
Dim AccessCommand As New OleDbCommand("U PDATE Table1 SET OLEField=? WHERE [record id] = 1",
AccessConnectio n)
Dim FileStreamObjec t As New System.IO.FileS tream(SourceFil ePath, IO.FileMode.Ope n,
IO.FileAccess.R ead)
Console.Write(F ileStreamObject .Length)
Dim PictureByteArra y(CType(FileStr eamObject.Lengt h() - 1, Integer)) As Byte
FileStreamObjec t.Read(PictureB yteArray, 0, PictureByteArra y.Length)
FileStreamObjec t.Close()
Dim QueryParameter As New OleDbParameter( "@Picture", OleDbType.LongV arBinary,
PictureByteArra y.Length, ParameterDirect ion.Input, False, 0, 0, Nothing, DataRowVersion. Current,
PictureByteArra y)
AccessCommand.P arameters.Add(Q ueryParameter)
AccessConnectio n.Open()
AccessCommand.E xecuteNonQuery( )
AccessConnectio n.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("picda ta"))
bmpFile = New Bitmap(stmFile)
stmFile.Read(by t, 0, byt.Length)

strConnStr =
ConfigurationSe ttings.AppSetti ngs("connString ")
Dim objConn As New OleDbConnection (strConnStr)
objConn.Open()

Dim DBCmd As New OleDb.OleDbComm and("UPDATE exproduct
SET pic=@pic WHERE id = 1207", objConn)
Dim P As New OleDb.OleDbPara meter("@pic",
OleDb.OleDbType .LongVarBinary, byt.Length, ParameterDirect ion.Input,
False, 0, 0, Nothing, DataRowVersion. Current, byt)
DBCmd.Parameter s.Add(P)
DBCmd.ExecuteNo nQuery()
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("picda ta"))
¤ bmpFile = New Bitmap(stmFile)
¤ stmFile.Read(by t, 0, byt.Length)
¤
¤ strConnStr =
¤ ConfigurationSe ttings.AppSetti ngs("connString ")
¤ Dim objConn As New OleDbConnection (strConnStr)
¤ objConn.Open()
¤
¤ Dim DBCmd As New OleDb.OleDbComm and("UPDATE exproduct
¤ SET pic=@pic WHERE id = 1207", objConn)
¤ Dim P As New OleDb.OleDbPara meter("@pic",
¤ OleDb.OleDbType .LongVarBinary, byt.Length, ParameterDirect ion.Input,
¤ False, 0, 0, Nothing, DataRowVersion. Current, byt)
¤ DBCmd.Parameter s.Add(P)
¤ DBCmd.ExecuteNo nQuery()
¤ 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
414
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 available in the database which I don't want to change. I think the trouble is in .net data type string which actually is a unicode string. I have an array of bytes (= binary data) which I need to pass somehow to the stored procedure which input...
2
2041
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 images and put them in one binary file, but couldn't figure out a way to do that, anyone has an idea? thanks
2
16658
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 open folder). When I accept, in the design form, appears in the ImageColumn the typical red cross of an image not found.
4
2354
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
8
4387
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. Unfortunately I cannot find an efficient way to do this in C#. I need to do this at 10fps+ with 1hour+ data files. My current approach is read a byte from the filestream, then create a MemoryStream to the created byte and then a bitmap from the memory
11
28332
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
2855
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 against, the data for the graph is only stored in the HTTPContext's Items collection, so the page that displays the graph is the only one with the data.
2
2571
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" method="post" name="registrationform"> Choose a shows:
1
5539
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 insert. Notice: (images are store as binary). Could anyone help me? Sandra
0
1406
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. Image type is Metafile. Whn I tried to copy from Clipboard, it didnt support the metafile. So is there any other method to insert an Image to WORD.
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8397
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8599
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.