Hello Friends....

I have a patient registration form in my project...in which I have to browse the image of the patient save it in the database and when I need the details of the patient again the uploaded image should also be displayed....

Please help me in this...

I have created a column in database which will save the filename and path of the image but I dont know as to how to call the image again for displaying purpose....

Dani AI

Generated

As noted, loading an image from a saved path is straightforward, but there are practical issues that often get overlooked: the file can remain locked, the app can leak GDI objects if images are not disposed, and absolute paths stored in a DB can break if files move. The short note below gives safer loading patterns, brief pros/cons of storage approaches, and quick troubleshooting tips that apply when revisiting this topic years later.

A safer pattern is to read the file bytes (or the varbinary blob from the database) into memory and create an Image from a MemoryStream, then clone the Bitmap so the original stream can be closed. That avoids locking the source file and makes it safe to replace or delete the original file later.

' VB.NET: load without locking the original file
Dim bytes() As Byte = System.IO.File.ReadAllBytes(pathFromDb)
Using ms As New System.IO.MemoryStream(bytes)
    Dim img = System.Drawing.Image.FromStream(ms)
    Dim bmp As New System.Drawing.Bitmap(img)   ' clone to detach from stream
    If pictureBox1.Image IsNot Nothing Then pictureBox1.Image.Dispose()
    pictureBox1.Image = bmp
    img.Dispose()
End Using

Quick checklist and tips:

  • Wrap file/DB reads in Try/Catch and check File.Exists before reading.
  • Dispose previous PictureBox.Image before assigning a new image to avoid leaks.
  • Prefer storing images in a controlled app folder and save relative paths in DB (safer than arbitrary user paths).
  • Consider storing the image bytes in the DB (varbinary) for portability, but note DB size and performance tradeoffs.
  • Validate file type and size on upload to avoid invalid content or very large images; resize on upload if necessary.

References: Image.FromStream, Image.FromFile, PictureBox.Image.

Hello Friends....

I have a patient registration form in my project...in which I have to browse the image of the patient save it in the database and when I need the details of the patient again the uploaded image should also be displayed....

Please help me in this...

I have created a column in database which will save the filename and path of the image but I dont know as to how to call the image again for displaying purpose....

Got it solved

PictureBox1.Image=Image.FromFile("FileName")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.