473,748 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

images Search from Database using sessions

2 New Member
I am facing a problem which is that when i search image from database then it just shows last image which is stored in the database.
my code is
Expand|Select|Wrap|Line Numbers
  1. private void Images()
  2.         {
  3.  
  4.             SqlConnection con = new SqlConnection("Data Source=chusman-pc;Initial Catalog=Hotel_Management;Integrated Security=True");
  5.             con.Open();
  6.  
  7.             SqlCommand com = new SqlCommand();
  8.             com.CommandType = CommandType.StoredProcedure;
  9.             com.CommandText = "Images_Search";
  10.             com.Parameters.AddWithValue("@Type", DropDownList3.Text);
  11.  
  12.  
  13.             com.Connection = con;
  14.             SqlDataReader r = com.ExecuteReader();
  15.  
  16.  
  17.             while (r.Read())
  18.             {
  19.                 Image1.ImageUrl = (string)r["Images"];
  20.                 //Image1.ImageUrl = r["Images"].ToString();
  21.                 Session["Id"] =   r["Project_id"];               
  22.                 r.Read();
  23.             }
  24.  
  25.             con.Close();
  26.  
  27.         }
I call this function at SelectedIndexCh anged of dropbox..
kindly tell me the issue..
Feb 14 '13 #1
4 1773
Rabbit
12,516 Recognized Expert Moderator MVP
In your query, have it select just the top 1 record and sort by the insert date in descending order.

That's as specific as I can get because you didn't give us the table design or the query you're running.
Feb 14 '13 #2
usmaaan
2 New Member
My Query Is
Expand|Select|Wrap|Line Numbers
  1. USE [hotel_man]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[Images_Search]    Script Date: 02/14/2013 20:37:09 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. ALTER PROCEDURE [dbo].[Images_Search]
  10. @Type as varchar(50)
  11. AS
  12. BEGIN
  13.     select Images, Project_Id   from  dbo.Images   where Type = @Type order by Sorting_Id asc
  14.  
  15.  
  16.  
  17.  
  18.  
  19. END
Feb 14 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

You didn't implement any of my suggestions in my first post.
Feb 14 '13 #4
Mikkeee
94 New Member
First off, how many records are being returned? You're in a while loop which will loop through all your records and will set your image and sessionid many times until it gets to the end. (you also have an additional r.Read() in your while loop which should be removed. Rabbit's TOP 1 will work perfectly or you need to bail out of your while loop after the first record is read.
Feb 14 '13 #5

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

Similar topics

0
1563
by: Lee | last post by:
Hello, This is a genral enquiry before I send out a more detailed request. I am unable to retreive image files from a mysql database using IE 5.2 on the mac OS X platform. I have built a database driven website that stores images as blob files. I specify the mime types and limit the file sizes to 15k. I can retreive the images using Windows, and Mac OS 9, but explorer
1
2369
by: Universal | last post by:
store Images (or any Binary Data) to a SQL Server database using VC++ Can anybody help me in this Thanks in advance
5
2073
by: PR | last post by:
Searchable product images + prices database? What system should I use to put a database on the WEB which shows images and allows searches, including searches within given price ranges for products? There will be product images too, thumbnails and larger images? All the data will be on a single server, on the same
1
1881
by: Al | last post by:
Hi, I need to store literally thousands if images and scanned document in the Database. I would like to know what is the most efficient algorithm both in terms of speed and storage for saving images in database (using SQL server). Currently I am using the following algorithms. Question is can I improve this? 'Get length of stream (lengt of file) in bytes InByteCount = loFile.Length() 'Reallocate storage space for an array variable to...
1
6658
by: nwebhosting | last post by:
Hello and thank you. Could you please help me with this.: i try to store images using the following code, and it just bring a blank screen. i being trying different things and i am not sure if the problem is on values. Please help me. PUT YOUR CODE WITHIN code OR php TAGS NEXT TIME!!!! <body> <form action="insert2.php"method="post" enctype="multipart/form-data">
0
1147
by: mathewgk80 | last post by:
Hi all, I want to store and retrieve images in database using asp.net,c#.net and sql server. Please help me, Regards, Mathew
0
1290
by: punitshrivastava | last post by:
Hi to All Senior's, I am working in Asp.net with C#. I am newbie in C#. So i want to fetch mutiple images from database .Database i am using is Sql Server. For this i code: //get the image id from the url string Imagename = DropDownList1.SelectedItem .Text ; //string Imagename = Request.QueryString; //build our query statementworkstation id=SOFTWARE3;packet size=4096;integrated security=SSPI;data source=SOFTWARE3;persist security...
1
1207
by: mathewgk80 | last post by:
Hi all, I would like to know how to store images in database as thumbnail and how to retrieve that images from database and display it in gridview. I am using sqlserver,c#.net and asp.net. Please help me.. Its very urgent... Thanks and Regards,
0
3273
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.*" %> <%
0
1374
by: kino | last post by:
I am trying to test storing images in a database, I got this code after searching on Google but it doesn't work: protected void Button1_Click(object sender, EventArgs e) { string strImageName = @"E:\images.jpg"; Bitmap bNewImage = new Bitmap(strImageName); FileStream fs = new FileStream(strImageName, FileMode.Open, FileAccess.Read); //creating byte array to read image
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9561
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
9381
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...
0
8252
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
6799
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
4608
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...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
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
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.