Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting images from database

Status
Not open for further replies.

choudhmh

Programmer
Aug 9, 2004
34
GB
Hi experts,

I am retriving information from the database, to this form. The form shows all the information from the database i request for. I have this field in the database where the values inserted are 1 and 0. Instead of retriving 1 and 0 to the form, i want to insert images. For value 1 there will be an image and the same for value 0 there will be an image. how will i specify the coding to insert image, and also how will i insert the image (retrive from the C:\ directory)Thsi is how at present of retrivig the information from the database:

String sQuery = "SELECT * FROM License WHERE Name = '"+ label1.Text +"' AND LicenseID = '"+ label2.Text +"'";

SqlCommand cmd = new SqlCommand(sQuery, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();

if( dr.Read() )

{
label26.Text = dr[ "Name" ].ToString();
label27.Text = dr[ "Description" ].ToString();
label29.Text = dr[ "price" ].ToString();
label36.Text = dr[ "playcount" ].ToString();
label34.Image = dr[ "AllowPlayOnPC" ].


where the table displays the text and numbers, but now for other fileds i want to display images. How would i go about doing this. I need to insert someything else instead of ToString() for the image, does anyone who what.

Thanks

 
Code:
if (Convert.ToBool(dr[ "AllowPlayOnPC" ]) == true)
    label34.Image = Image.FromFile("C:\\Image1.jpg")
else
    label34.Image = Image.FromFile("C:\\Image2.jpg")
 
Hi Korach,
Thanks for your reply, i'm getting one error with the above code.
'System.Convert' does not contain a definition for 'ToBool'.

but i figured out the answere this is how i done this and it functions perfectly:

f (Convert.ToInt32(dr[ "AllowPlayOnPC" ]) == 1 ? true : false)
label34.Image = Image.FromFile(@"C:\Documents and Settings\encode\My Documents\My Pictures\\greentick.gif");
else
label34.Image = Image.FromFile("C:\\Image2.jpg");

Thanks,
Mac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top