Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use same form for new and updating record in visual c#

I am building a simple app in c# using Visual C# 2010 Express. I have created a data entry form which captures some data.

I'd like to use that same form for when a user wants to edit some data. How would I go about writing the code to tell the form that it's in edit mode, so load recordID=4431. If it's not in edit more, then just blank and add a new record when save is pressed.

Any thoughts?! Cheers, Matt.

like image 987
Matt Facer Avatar asked Jan 27 '26 18:01

Matt Facer


2 Answers

There a few ways of doing this. The simplest would be adding a hidden field to your form that would contain the ID of the object in edition, or null if it's a new submission.

Regards

like image 138
Andre Calil Avatar answered Jan 30 '26 06:01

Andre Calil


Well,

I have done this before. What I did was create a function that retrieves the data for specified record. This function will then just populate the fields in the form.

To tell the form it's in edit mode I just use a boolean to specify this. It is also necessary to store the record being edited so you can update it after.

Is this what your looking for or do you want code samples?

like image 24
jim Avatar answered Jan 30 '26 08:01

jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!