question

mortadhanaser-4329 avatar image
0 Votes"
mortadhanaser-4329 asked karenpayneoregon edited

How to check the current record if new record?

I have windows form application is connected to database with dataset and using bindingsource ,i make the form go to new record when form load by Addnew() in form_load event, i put combobox to filter bindingsource , but i have error if current record is new record because the controls is empty, if form in another saved record the filter is worked correctly, how to check if form current record is new record or no , and if new record true cancel the new record ?

dotnet-visual-basic
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.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered karenpayneoregon edited

Depending on how this is being coded the primary key is -1 and when saved assuming the primary key is auto-incrementing for SQL-Server the primary key will be the new key, while with MS-Access for instance you need to reload which of course does not help.

There are also events you can subscribe too and AddingNew event for the BindingSource

Also, the above assumes you have no called AcceptChanges, this should not be called on any DataTable or DataRow.


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.