473,666 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 4898
vijay6
158 New Member
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
helsywarner
1 New Member
Dim image As Byte() = DirectCast(comm and.ExecuteScal ar(), Byte())
stream.Write(im age, 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
MadhaviN
1 New Member
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
20905
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 contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
6
7841
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 a memory stream. The problem I'm having is when the page comes up, only the first image is shown. If I save each page off in a file I can see that each page is unique and it's not a problem with the stream, it seems to be a problem with...
5
2943
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>") Response.WriteFile("images/image003.jpg") Response.Write("<br><p>") Any help? Thanks
4
6335
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 top goal scorers from the database and how many goals they have scored, but against their name i want to repeat a football image the number of times they have scored and keep it dynamic to the database, is there any way of doing a repeating region...
0
1408
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 able to print either the first image or the last image. Am giving my code also here. int count = Convert.ToInt32(Session); object label = new object; Response.ClearContent(); ...
11
4157
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 user's related images like below: Id First Name Last Name Title Image1 Image2 Image3
5
2203
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 mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("rainlist"); $result = mysql_query(sprintf("SELECT * from pix WHERE pid = 1", $_GET)); echo "SELECT * from images WHERE pid=".$_GET;
11
10810
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 = mysql_query("SELECT * FROM paintings"); while($row = mysql_fetch_assoc($result)){ print $row."</br>"; //print $row; }
0
3259
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. <%@ page import ="java.sql.*,java.util.*,java.awt.*,java.io.*" %> <%
1
2365
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. Here's the html and the perl code: html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> <html> <form action="http://localhost/code.pl" method="post" target="_blank" enctype="multipart/form-data" >
0
8871
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
8783
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
8552
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
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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
6198
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.