473,406 Members | 2,377 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,406 software developers and data experts.

How to save iamge in database?

Dear All

Can anyone tell me how to save an JPEG image in a database table field?

Below is the code that I have wrote but it gives an error:
System.InvalidCastException
Object must implement IConvertible

DatabaseAccess.SqlConnection.Open()

picDataAdapter.InsertCommand = New SqlCommand("INSERT INTO TheImage(AppNo,
theImage) VALUES(@appno, @theImage)", DatabaseAccess.SqlConnection)

picDataAdapter.InsertCommand.Parameters.Add("@appn o", SqlDbType.Int).Value =
AppNo

picDataAdapter.InsertCommand.Parameters.Add("@theI mage", SqlDbType.Image,
7000).Value = MyImage

picDataAdapter.InsertCommand.ExecuteNonQuery()

DatabaseAccess.SqlConnection.Close()

TheImage table has two fields:

AppNo int

theImage Image

myImage is of Image type

Waiting for reply... Thanks in advance

Regards

Ishtiaque Ahmed Memon

Jul 31 '06 #1
1 1011
Hi,

You need to convert the image to a byte array to save it in a
database. There is an example in this tip.

http://www.vb-tips.com/dbpages.aspx?...6-38b5a2f7fdf0

Ken
-------------------
"Ishtiaque Ahmed Memon" <is*********@yahoo.comwrote in message
news:Ob**************@TK2MSFTNGP06.phx.gbl...
Dear All

Can anyone tell me how to save an JPEG image in a database table field?

Below is the code that I have wrote but it gives an error:
System.InvalidCastException
Object must implement IConvertible

DatabaseAccess.SqlConnection.Open()

picDataAdapter.InsertCommand = New SqlCommand("INSERT INTO TheImage(AppNo,
theImage) VALUES(@appno, @theImage)", DatabaseAccess.SqlConnection)

picDataAdapter.InsertCommand.Parameters.Add("@appn o", SqlDbType.Int).Value
=
AppNo

picDataAdapter.InsertCommand.Parameters.Add("@theI mage", SqlDbType.Image,
7000).Value = MyImage

picDataAdapter.InsertCommand.ExecuteNonQuery()

DatabaseAccess.SqlConnection.Close()

TheImage table has two fields:

AppNo int

theImage Image

myImage is of Image type

Waiting for reply... Thanks in advance

Regards

Ishtiaque Ahmed Memon



Jul 31 '06 #2

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

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
5
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would like to save it to "My Documents". We have had...
7
by: joseph.inglis | last post by:
I have a web browser object on a form which I have set to edit mode and use the UCOMIConnectionPointContainer interface to hook in and catch events. All working sweetly. Except there...
7
by: Shanli RICHEZ | last post by:
I'm using ASP.NET and quite a lot of object in memory instead of a database. The question is that I tried to save the data, serialize them in a XML file to save them when the application is...
4
by: xAvailx | last post by:
Hello: I didn't find any documentation that notes save point names are case sensitive, but I guess they are... Stored Proc to reproduce: /* START CODE SNIPPET */ If Exists (Select * From...
6
by: Josetta | last post by:
Access 2003 I've been experiencing some problems with my "monster" database the last couple of days. I imported all objects into a new database yesterday, which pretty much stopped the crashing...
1
by: TonyJ | last post by:
Hello! I'm using VS2005. I'm looking at ADO.NET and have found some test tutorial solution on microsoft MSDN. The one that I'm looking at now is called Walkthrough: Saving Data to a Database...
2
by: chike_oji | last post by:
Please can someone help me. I am writing a web application, that allows for the upload of an excel sheet into the database. I have an upload button and a save button. The upload button allows...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
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?
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
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,...
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
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,...
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.