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

Display image on C# web page through ms-access

3
Hi everyone!!
I m trying to display jpg image from ms-access database on C# web page. Image is stored as OLE object under "img_stream" variable in database. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");
  2.  
  3.         // Object created for Oledb Connection
  4.         OleDbConnection myAccessConnection;
  5.  
  6.         protected void openAccessConnection()
  7.         {
  8.             // If condition that can be used to check the access database connection
  9.             // whether it is already open or not.
  10.             if (myAccessConnection.State == ConnectionState.Closed)
  11.             {
  12.                 myAccessConnection.Open();
  13.             }
  14.         }
  15.  
  16.         protected void closeAccessConnection()
  17.         {
  18.             // If condition to check the access database connection state
  19.             // If it is open then close it.
  20.             if (myAccessConnection.State == ConnectionState.Open)
  21.             {
  22.                 myAccessConnection.Close();
  23.             }
  24.  
  25.         }
  26.  
  27.    private void Page_Load(object sender, System.EventArgs e)
  28.    {
  29.         // Put user code to initialize the page here
  30.        myAccessConnection = new OleDbConnection(connStr);
  31.        openAccessConnection();
  32.        OleDbCommand myCommand = new OleDbCommand("select    img_stream from tblImg where img_id=4", myAccessConnection);
  33.       //OleDbParameter img_id = new OleDbParameter("4", OleDbType.Integer);
  34.      //myCommand.Parameters.Add(img_id);
  35.       OleDbDataReader reader = myCommand.ExecuteReader();
  36.       if(reader.Read())
  37.       {
  38.          Response.ContentType = "image/jpeg";
  39.          byte[] imageContent = (byte[])(reader["img_stream"]);
  40.          ms.Write(imageContent, 0, imageContent.Length);
  41.          Bitmap bmp = null;
  42.          bmp = new Bitmap(ms);
  43.          bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
  44.          ms.Close();
  45.          closeAccessConnection();
  46.      }
  47.      else
  48.      {
  49.         closeAccessConnection();
  50.      }
  51. }
On executing code i get the following error:
"Invalid Parameter Used"
Error is at: bmp = new Bitmap(ms);
Please help me to resolve this problem. I will highly obliged as i have passed so much time in finding and resolving this error but no way out :-(
Aug 7 '08 #1
3 3142
Curtis Rutland
3,256 Expert 2GB
Where did you define ms?
Aug 7 '08 #2
nudma
3
Where did you define ms?
I'm sorry that got deleted by me, by mistake...Here it is:
if(reader.Read())
{
MemoryStream ms = new MemoryStream();
Response.ContentType = "image/jpeg";
byte[] imageContent = (byte[])(reader["img_stream"]);
ms.Write(imageContent, 0, imageContent.Length);
Bitmap bmp;
bmp = new Bitmap(ms);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
ms.Close();
closeAccessConnection();
}
else
{
closeAccessConnection();
}
Please check it out and help me out to resolve my error...
Aug 8 '08 #3
nudma
3
I'm sorry that got deleted by me, by mistake...Here it is:
if(reader.Read())
{
MemoryStream ms = new MemoryStream();
Response.ContentType = "image/jpeg";
byte[] imageContent = (byte[])(reader["img_stream"]);
ms.Write(imageContent, 0, imageContent.Length);
Bitmap bmp;
bmp = new Bitmap(ms);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
ms.Close();
closeAccessConnection();
}
else
{
closeAccessConnection();
}
Please check it out and help me out to resolve my error...
Dear All!!
I m still solution less..Please help me...
Aug 12 '08 #4

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

Similar topics

1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
1
by: pkamil83 | last post by:
Hello I've got a table on SQL Server 2005 with columns: ID int Text XML Image varbinary(max) In this table I'm having SVG images. All I have to do is to display those images on ASP.NET 2...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
17
by: seajay | last post by:
Hello, I noticed something strange when I was composing a XHTML document with CSS The following DOCTYPE causes the page to display differently on Fireflox 1.0.6 and Internet Explorer 6...
0
by: manjitsarma | last post by:
I need to display an image in 'Image Control' of aspx page.Now the image is displayed in the aspx page itself.But I need to display it in 'Image Control'.This is a map application and the image is...
9
by: Mel | last post by:
I have some Asp.net 2.0/vb.net code that creates a gantt chart with some dependencies as a new MS Project (.mpp) file. How would I show this resulting .mpp file on an Asp.net webpage? I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.