What's new

C# How to display photo from database to picturebox?

PHC_Rubiin

Eternal Poster
Established
Joined
Jan 5, 2018
Posts
592
Reaction
212
Points
331
Age
22
How to display photo from database to picturebox?
 
To display a photo from a database to a PictureBox control, you'll need to follow these general steps:

1. Retrieve the photo from the database: First, you'll need to retrieve the photo data from the database. The specific method for this will depend on the database you're using.

2. Convert the photo data to an image: Once you have retrieved the photo data, you'll need to convert it to an image object. You can use the MemoryStream class in .NET to achieve this. Here's an example using C#:

C#:
byte[] photoData = // retrieve photo data from the database

using (MemoryStream ms = new MemoryStream(photoData))
{
    Image image = Image.FromStream(ms);
}

3. Assign the image to the PictureBox control: Finally, you can assign the image object to the PictureBox control's Image property to display it. Here's an example:

C#:
pictureBox1.Image = image; // assuming pictureBox1 is the name of your PictureBox control

Make sure to adjust the code based on your specific database and programming language.
 
naka byte ba yung format ng picture mo sa database?
baka mamaya naka full path + file name lang yung data na nasa database hindi talga mag wowork yan
 
Ito TS gumagana saken. Ginawa ko since hindi ako ang gumawa ng database, retrieve ko data and store photo into temp files and retrieve it back. Ginamit ko yung nwind database ni Microsoft.


Output:
Capture.JPG


Please make a feedback. sana makatulong.
 

Attachments

Last edited:
naka byte ba yung format ng picture mo sa database?
baka mamaya naka full path + file name lang yung data na nasa database hindi talga mag wowork yan
Ito TS gumagana saken. Ginawa ko since hindi ako ang gumawa ng database, retrieve ko data and store photo into temp files and retrieve it back. Ginamit ko yung nwind database ni Microsoft.

View attachment 2821646

Output:
View attachment 2821649

Please make a feedback. sana makatulong.
naka byte ba yung format ng picture mo sa database?
baka mamaya naka full path + file name lang yung data na nasa database hindi talga mag wowork yan
Okay na mga idol devs. nagawan ko ng paraan nung isang araw pa. thank you sa pag babahagi ng kaalaman!
 

Similar threads

Back
Top