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

How to display multiple images from sql server 2005 into c# at runtime.

1
I STORED MULTIPLE IMAGES IN MY SQL SERVER 2005. NOW I WANT TO RETRIEVE PARTICULAR CATEGORY OF IMAGES INTO MULTIPLE PICTUREBOX AT RUNTIME IN C# WINDOWS APPLICATION. i used the following code in my final result form at form_Load using c# windows apps.. But it displays only one picture at run time pls help to me...


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. SqlConnection con = new SqlConnection(@"Data Source=ttt-PC;Initial Catalog=Query_Image;Integrated Security=True");
  5.             SqlCommand cmdnew = new SqlCommand("select pic from Image_Category where IMG_Cat='" + searchvalue.ToString() + "'", con);
  6.             con.Open();
  7.           //  SqlDataReader dr = cmdnew.ExecuteReader();
  8.             SqlDataAdapter da = new SqlDataAdapter(cmdnew);
  9.             DataSet ds = new DataSet("Image_Category");
  10.             byte[] mydata = new byte[0];
  11.             da.Fill(ds, "Image_Category");
  12.             DataRow myrow;
  13.             //if (dr.HasRows)
  14.             //{
  15.             //    while (dr.Read())
  16.             //    {
  17.  
  18.             for (int i = 0; i < 2; i++)
  19.  
  20.             // while (i <= dt.Rows.Count)
  21.  
  22.             {
  23.  
  24.                 myrow= ds.Tables["Image_Category"].Rows[i];
  25.                 mydata = (byte[])ds.Tables[0].Rows[i]["pic"];
  26.                 str[i]=new MemoryStream(mydata);
  27.  
  28.                 pbx[i]=new PictureBox();
  29.                  pbx[i].Size = new Size(150, 150);
  30.                  pbx[i].SizeMode = PictureBoxSizeMode.StretchImage;
  31.                 pbx[i].BackgroundImage = Image.FromStream(str[i]);
  32.                  pbx[i].Visible = true;
  33.                  //this.Controls.Add(pbx[i]);
  34.                 }
  35.  
PLEASE TELL IS IT ANY WRONG WITH THIS CODE?
OR SUGGEST NEW CODE TO ME PLEASE..
Mar 26 '13 #1
3 4875
vijay6
158 100+
Hey rajmca, your code is right but you forgot to use the PictureBox location property. So by default all the PictureBoxes uses same location (One above one). So that only you're seeing only one PictureBox (the PictureBox which created atlast) at runtime. Include these lines and try,

Expand|Select|Wrap|Line Numbers
  1. // Above for loop
  2.  
  3. int x = 10;
  4. int y = 10;
  5.  
  6. // Inside for loop
  7.  
  8. pbx[i].Location = new Point(x, y);
  9. x += pbx[i].Location.X + pbx[i].Width;

And one more thing is you've to use Image property not BackgroundImage property in line #31 in your code.

Expand|Select|Wrap|Line Numbers
  1. //pbx[i].BackgroundImage = Image.FromStream(str[i]); // Instead of this line use the following line.
  2. pbx[i].Image = Image.FromStream(str[i]);
Apr 3 '13 #2
Dim image As Byte() = DirectCast(command.ExecuteScalar(), Byte())
stream.Write(image, 0, image.Length)


you can retreve each image and put it into bitmap.

http://net-informations.com/vbprj/da...ieve-image.htm

helsy
Apr 23 '13 #3
getting error on pbx n str so wht to do...i want to retreive multiple images in picturebox from database when the form is loaded..
Aug 7 '16 #4

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

Similar topics

12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
6
by: Richard | last post by:
Hello, I have a multipage tiff file which I am trying to output to a web browser using Response.BinaryWrite. I am taking the tiff file, then looping for each page and saving it off to a jpg in...
5
by: david | last post by:
Can I use WriteFile methods? It seems that it does not work. For example, the following code only dispay one figure. Response.WriteFile("images/image002.jpg") Response.Write("<br><p>")...
4
by: Milkstr | last post by:
I want to be able to display the same image a number of times, according to how is set by my database that drives the page. I have database of top goal scorers, i know how to display a list of the...
0
by: Linta | last post by:
Hi, Actually i want to display mutiple images using BinaryWrite method. I am able to store all the images in an object.My problem is that i couldnt display all that images in the browser. I am...
11
by: Jankie | last post by:
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images. I only want 1 entry to display all of a...
5
by: swethak | last post by:
Hi,. when i display the image by using below code i got the error as image displayed in the form of garbage value format.plz tell that what's the mistake in my code. <?php...
11
by: nse111 | last post by:
<?php //header('Content-Type: image/jpeg'); header('Content-Type: text/html'); @mysql_connect("localhost","root","dba") or die("Error"); @mysql_select_db("gallery"); $result =...
0
selvasoft
by: selvasoft | last post by:
Hi Please help me any one. I want solution for display multiple images from oracle database.Using JSP. here is my code for display one image from database. Please Any one give me some ideas. ...
1
by: ronnie gordon | last post by:
Hi... I have 4 pics ( jpeg) in an array, but i'm having trouble displaying them all. It never displays all pics, tends to display them in random order, and sometimes pics are repeated 2 or 3 times. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.