Loading and Displaying Images

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using SQL Server 2000. I have a table with (name, address, photo)
information. I have stored some photos in a folder on the 'D drive'. In the
sql table I point to where the photos are ('D:\kennel\photos\bonnie.jpg'). I
then do a select statement to retrieve the info but I cannot display the
photos. Can some one point me to a place to read about how to do this, or
show me how? Please Help!!
 
Following is the select statement that I use to retrieve the data, the line
with the *** is the line thats gets the photo.

strSQL = "SELECT [pet-id], [owner-id], [pet-name], [sp-nu], [pet-type],
[pet-breed], [pet-sex], [pet-weight], [pet-size], [pet-color],
[pet-age-years], [pet-age-months], rate, [rate-type], compatable,
[medical-condition], [pet-location], [animal-tag-id], [animal-implanted-id],
[pet-photo] FROM [animal-info] WHERE [pet-id] = " + PrepareStr(txtOid.Text);

cmSQL = new SqlCommand(strSQL, cnKennel);
if (cnKennel.State != ConnectionState.Open)
cnKennel.Open();
drSQL = cmSQL.ExecuteReader();

if(drSQL.Read())
{
txtAnimalID.Text = drSQL["pet-id"].ToString();
txtOid.Text = drSQL["owner-id"].ToString();
txtAnimalName.Text = drSQL["pet-name"].ToString();
cbSpNu.Text = drSQL["sp-nu"].ToString();
cbAnimalType.Text = drSQL["pet-type"].ToString();
cbAnimalBreed.Text = drSQL["pet-breed"].ToString();
cbAnimalSex.Text = drSQL["pet-sex"].ToString();
txtAnimalColor.Text = drSQL["pet-color"].ToString();
txtAnimalWeight.Text = drSQL["pet-weight"].ToString();
cbAnimalSize.Text = drSQL["pet-size"].ToString();
txtAnimalAgeYears.Text = drSQL["pet-age-years"].ToString();
txtAnimalAgeMonths.Text = drSQL["pet-age-months"].ToString();
cbRate.Text = drSQL["rate"].ToString();
cbRateType.Text = drSQL["rate-type"].ToString();
cbCompatable.Text = drSQL["compatable"].ToString();
txtAnimalMedicalCondition.Text = drSQL["medical-condition"].ToString();
txtAnimalLocation.Text = drSQL["pet-location"].ToString();
txtAnimalTag.Text = drSQL["animal-tag-id"].ToString();
txtAnimalImpId.Text = drSQL["animal-implanted-id"].ToString();
*** pcAnimalPhoto.Text = drSQL["pet-photo"].ToString(); ***
}
 
Hi Norm

Is the Pets Photo stored in the database?
If Yes then the *** line shows that u are converting that into a string
(What does that mean)

According to me if u have a Photo in the database then u need to read
it as binary data.

Regards
 
No the photos are not stored in the database. I was trying not to store them
there, but I might have to if you suggest that?
 
Norm,

If the database stores only the path to the photo, you need to use either a
standard control, or the System.Drawing namespace to read that image from
the specified path and render it out on the screen.

What specific code depends on if you are using a winforms app, or a web
based, and if it is VS2003 or VS2005.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
Back
Top