Handling a null value parameter for a field with a default value

Declan_Basile
Declan_Basile used Ask the Experts™
on
There's a field in a table of a SQL Server database that doesn't except "NULL" but has a default value of "0".  The InsertCommand for the data adapter that vb.net automatically  generates doesn't accommodate this. If the field is left blank in the front end program, the update method of the data adapter fails with a message that the field can't be left blank.  It doesn't set it to the default value that is set in the SQL Server table.  What is the easiest way to get the data adapter to set the field to the default value when the corresponding parameter is null (from being left blank by the user)?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You may create your own InsertCommand without the given column (http://vb.net-informations.com/dataadapter/dataadapter-insertcommand-sqlserver.htm) or you may create a view without the given column on SQL Server and use it in InsertCommand generated automatically (https://www.w3schools.com/sql/sql_view.asp).

Author

Commented:
Thank you.
Mark EdwardsChief Technology Officer

Commented:
Just a note:  "default" values are only inserted when the record is created.  If you delete the value in the field, SQL Server will NOT replace it with the default value.  You'll need to program your UI to handle this, or change whatever process is deleting the value in the field if that is where the deletion is occurring.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial