question

MichelleKamp-0682 avatar image
0 Votes"
MichelleKamp-0682 asked LeoZacche-MAG answered

C# how to map to a photo

I am new to C# and need to know how code and map to a student photo. In my example below, when a person selects Student Details for a student, it would go to a student details form. In this form, it would have a photo of the student and other class information.
How do I go about coding that select student to their photo which is located on a local directory, and the photo is named the student id. The student id would be the primary key.

Thank you

198894-image.png


dotnet-csharpc++
image.png (348.8 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MichelleKamp-0682, Welcome to Microsoft Q&A, based on your description, I have some questions to confirm with you.
Do you want to save the photo information to the database? where the photo name is shown in the winform?

0 Votes 0 ·

1 Answer

LeoZacche-MAG avatar image
0 Votes"
LeoZacche-MAG answered

Hi @MichaelHan-MSFT.

Whenever your user selects (clicks) the "Student Details" button, you will open the "Student_Details" form to show the deails. You need to pass the ID of the student to this form. There are several ways to do this (eg: call a method on the newly instantiated form, pass as parameter to a non-default constructor, pass the form as parameter to a method that you fill it, etc), so it is better to see your code to better help you.

Once you have the ID, it is easy to build the file name (including the path) of the picture to be displayed as a photo. To actually display depends on the control you are using. Is it a PictureBox? Any other control? The PictureBox seems to me to be easier to use.

Either way, you have to have the IDs of the students associated to each line of your grid. It seems you already have it (the second column). If so, just use it. If not, you have to store the ID somewhere in the line. It can be a (new) visible column or an invisible column (not visible but available to use it in code). Again, it is easier to help you if we see you code.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.