view images from database c#

view images from database c#

Page 1 of 1

4 Replies - 5074 Views - Last Post: 01 December 2010 - 06:02 AM Rate Topic: -----

#1 angeleabela18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 10

view images from database c#

Posted 25 November 2010 - 12:11 AM

Hi I am creating a website whereby the users need to click a button called 'more info' and it will redirect them to another page with the item's details. however i can't retrieve the images from the database. The text details are working fine. I have the following code:


aspx:

<div id=image1>
<asp:Image ID="img1" runat="server" Height="120px" Width="100px" />
</div>


<div id=image2>
<asp:Image ID="img2" runat="server" Height="120px" Width="100px" />
</div>
<div id=image3>
<asp:Image ID="img3" runat="server" Width="100px" />
</div>
<div id=image4>
<asp:Image ID="img4" runat="server" Height="120px" Width="100px" />
</div>
<div id=image5>
<asp:Image ID="img5" runat="server" Height="120px" Width="100px" />
</div>

<div id=text>

<asp:Label ID=type runat=server Text="Type:"></asp:Label>

<br />

<asp:Label ID=refno runat=server Text="Reference Number:"></asp:Label>
<br />


<asp:Label ID=noofbedrooms runat=server Text="Bedrooms:"></asp:Label>

<br />


<asp:Label ID=price runat=server Text="Price:"></asp:Label>

<br />

<asp:Label ID=locality runat=server Text="Locality:"></asp:Label>

<br />

<asp:Label ID=description runat=server Text="Description:"></asp:Label>

<br />



</div>

<div id=text2>

<asp:Label ID=type1 runat=server></asp:Label>
<br />
<asp:Label ID=reference runat=server></asp:Label>
<br />
<asp:Label ID=bedrooms runat=server></asp:Label>
<br />
<asp:Label ID=price1 runat=server></asp:Label>
<br />
<asp:Label ID=loc runat=server></asp:Label>
<br />
<asp:Label ID=desc runat=server></asp:Label>

</div>



C#


protected void Page_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
{
string s = Request.QueryString["RefNo"].ToString();
string select = "SELECT RefNo, Price, Location, Type, NoOfBedrooms, Description, Image_Path1, Image_Path2, Image_Path3, Image_Path4, Image_Path5 FROM Properties WHERE RefNo = " + s + "";


SqlConnection con = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(select, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{

reference.Text = dr[0].ToString();
price1.Text = dr[1].ToString();
loc.Text = dr[2].ToString();
type1.Text = dr[3].ToString();
bedrooms.Text = dr[4].ToString();
desc.Text = dr[5].ToString();

}

con.Close();
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: view images from database c#

#2 agent1   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 73
  • Joined: 09-July 10

Re: view images from database c#

Posted 25 November 2010 - 04:25 AM

well your images are not actually in the database, it looks like you are only storing the path to the image in the db, and you don't have any code that is setting anything to your images, the image wont display unless you set its its image property..

a quick count shows you have five images on the page but nowhere are you assigning images to them, you are pulling back the image paths in your sql query, they are inside your reader but you are doing nothing with them...

This post has been edited by agent1: 25 November 2010 - 04:27 AM

Was This Post Helpful? 0
  • +
  • -

#3 angeleabela18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 10

Re: view images from database c#

Posted 25 November 2010 - 04:33 AM

so i have to set the datatype in the database to images?
Was This Post Helpful? 0
  • +
  • -

#4 angeleabela18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-November 10

Re: view images from database c#

Posted 01 December 2010 - 05:20 AM

can you help me further please as i havent resolved the issue yet?
Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: view images from database c#

Posted 01 December 2010 - 06:02 AM

you don't have to save the images in the database if you are storing the images in a folder and are storing their path in the database. However, you do need to set the source of each image to the path in the database. In the code you provided above you are retrieving multiple image_path's from the database but you never do anything with those values, you need to assign them to the ImageUrl attribute of the images.

This post has been edited by Nakor: 01 December 2010 - 06:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1