473,378 Members | 1,404 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,378 software developers and data experts.

Image Insertion & Retrieve using Vb.Net2005

mafaisal
142 100+
Hello Experts

I am Using VB.Net 2005 And Sql 2005
I Want to Insertion of Image in to DataBase And its Retrievel And Also Passing of Images to Crystal Reports
I am searching For This
B coz I Have Table Company In that Company Name Addres Phno And Logo of Company,
In All Reports I Pass this Name & Address as PArameter in Crystal Report
also I Wantthe Logo in All report, then Hw to PAss This

If any one Use Like this Plz give The Code of Insertion, Retrieval And Passing of Images to report

Thanx in Advance

Faisal
Mar 14 '08 #1
2 1818
balabaster
797 Expert 512MB
Hello Experts

I am Using VB.Net 2005 And Sql 2005
I Want to Insertion of Image in to DataBase And its Retrievel And Also Passing of Images to Crystal Reports
I am searching For This
B coz I Have Table Company In that Company Name Addres Phno And Logo of Company,
In All Reports I Pass this Name & Address as PArameter in Crystal Report
also I Wantthe Logo in All report, then Hw to PAss This

If any one Use Like this Plz give The Code of Insertion, Retrieval And Passing of Images to report

Thanx in Advance

Faisal
Depending on what type of database you are using will change the procedure a little but I will give you an example for SQL Server:

Firstly, the field you need to store the data in your database needs to be binary.

Secondly read your image file as a byte array:

Expand|Select|Wrap|Line Numbers
  1. 'Writing file to database
  2. Dim oFile As New FileInfo("C:\MyFile.jpg")
  3. Dim oCmd As New SqlCommand("Insert into Images(ImageName, ImageData) Values(@FileName, @FileData)", oCon)
  4. oCmd.Parameters.AddWithValue("FileName", oFile.Name)
  5. oCmd.Parameters.AddWithValue("FileData", System.IO.File.ReadAllBytes(oFile.FullName))
  6. oCmd.ExecuteNonReader()
  7.  
  8. 'Reading from database
  9. Dim oCmd As New SqlCommand("Select ImageName, ImageData From Images", oCon)
  10. Dim oRdr As SqlDataReader = oCmd.ExecuteReader()
  11. System.IO.File.WriteAllBytes("C:\Images\" & oRdr("ImageName"), oRdr("ImageData"))
For a crystal report, you'd need to pass the byte array into a stream before loading an image object instead of writing the image to disk.

Expand|Select|Wrap|Line Numbers
  1. Dim oDataBytes() As Byte = oRdr("ImageName")
  2. Dim oDataStrm As New System.IO.MemoryStream(oDataBytes)
  3. Dim oImage As Image = Image.FromStream(oDataStrm)
You would then put the image object onto your crystal report... which I haven't done for years, so I'm afraid you're on your own for that part.
Mar 14 '08 #2
mafaisal
142 100+
Hello balabaster
Thanx For Your Reply
I will Try Now

Faisal

Depending on what type of database you are using will change the procedure a little but I will give you an example for SQL Server:

Firstly, the field you need to store the data in your database needs to be binary.

Secondly read your image file as a byte array:

Expand|Select|Wrap|Line Numbers
  1. 'Writing file to database
  2. Dim oFile As New FileInfo("C:\MyFile.jpg")
  3. Dim oCmd As New SqlCommand("Insert into Images(ImageName, ImageData) Values(@FileName, @FileData)", oCon)
  4. oCmd.Parameters.AddWithValue("FileName", oFile.Name)
  5. oCmd.Parameters.AddWithValue("FileData", System.IO.File.ReadAllBytes(oFile.FullName))
  6. oCmd.ExecuteNonReader()
  7.  
  8. 'Reading from database
  9. Dim oCmd As New SqlCommand("Select ImageName, ImageData From Images", oCon)
  10. Dim oRdr As SqlDataReader = oCmd.ExecuteReader()
  11. System.IO.File.WriteAllBytes("C:\Images\" & oRdr("ImageName"), oRdr("ImageData"))
For a crystal report, you'd need to pass the byte array into a stream before loading an image object instead of writing the image to disk.

Expand|Select|Wrap|Line Numbers
  1. Dim oDataBytes() As Byte = oRdr("ImageName")
  2. Dim oDataStrm As New System.IO.MemoryStream(oDataBytes)
  3. Dim oImage As Image = Image.FromStream(oDataStrm)
You would then put the image object onto your crystal report... which I haven't done for years, so I'm afraid you're on your own for that part.
Mar 15 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: B Squared | last post by:
I'm trying to pass a filename (which is a jpeg image) to a php function / file so that it will display. I know that its simple to get PHP to display an image hardcoding in the filename. For...
28
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching...
3
by: computer_guy | last post by:
Hi Everyone, I run into a problem. I am trying to write an aspx that can dynamically generate an image based on some input parameters. Things are very simple if the size of the parameters is...
6
by: googletired | last post by:
Hello, I haven't made a XSL in quite sometime so i am very rusty. Basicly i want the XSL to display a defined image if one is not present in the XML. here is my current XSL and XML will be...
0
mafaisal
by: mafaisal | last post by:
Hi Everybody I am Using Vb.net 2005 My Error when i Retrieve imge file from sql2005 database parameter not valid error is coming my code is Dim Logo As Byte() = RsC.Fields("Logo").Value
2
mafaisal
by: mafaisal | last post by:
Hi Everybody I am Using Vb.net 2005 My Error when i Retrieve imge file from sql2005 database my code is Dim Logo As Byte() = RsC.Fields("Logo").Value Dim stream As System.IO.MemoryStream
1
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using vb.net2005 And sql2005 See The Attachment This is Error When i retrieve image from Db I store Picture as datatype image Please See The Attachment
2
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using VB.Net 2005 And Sql 2005 I Want to Insertion of Image in to DataBase And its Retrievel And Also Passing of Images to Crystal Reports I am searching For This B coz I...
0
by: dipalipatel | last post by:
Hi, I have a very hard time to insert Image into Sqlce Database. Table : Test Column : mypic Datatype : image below the code while i am inserting
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.