开发者

c# Winform best way to update form?

I am trying to update a selected record using this code when closing the form:

interestsTableAdapter.Update(newCityCollectionDataSet);

The record is NOT updating doing this. I use the same code to update datagridviews bu开发者_运维百科t I do it while it is validating. Is there a better way to do this with FORMS as opposed to controls?


Why this isn't working could depend on when you're trying to save your record. There's a big difference between executing code before your form's closing and while your form's closing.

Typically, failures while the form's closing (in handlers of a Form's FormClosed event) are caused by the application exiting before the handler gets a chance to do its job.

On the other hand, handlers of a Form's FormClosing event are invoked before the form even starts to close, and can even keep it from closing. These handlers are almost always waited for, as long as the form is the application's "main" or "startup" form (and not a child of it).

Without seeing more code than what you've provided, I'm afraid it's all I can do to advise you to execute your code before the form closes (via its FormClosing event), rather than while it's closing (via its FormClosed event).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜