#️⃣ C# 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.
 
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.
 
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!
 

About this Thread

  • 8
    Replies
  • 1K
    Views
  • 4
    Participants
Last reply from:
PHC_Rubiin

Trending Topics

Online now

Members online
1,207
Guests online
1,432
Total visitors
2,639

Forum statistics

Threads
2,273,458
Posts
28,949,640
Members
1,235,752
Latest member
hojerry7
Back
Top