How to check the current record if new record?

mortadha naser 1 Reputation point
2021-05-26T09:35:58.487+00:00

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 ?

Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-05-26T16:58:45.52+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.