locked
FAQ Item: SQL Server’s default value is not set correctly when adding new rows from typed dataset. RRS feed

  • Question

  • SQL Server’s default value is not set correctly when adding new rows from typed dataset.
    Sunday, June 20, 2010 3:31 PM

Answers

  • The SQL Server default is invoked only if no value is specified for the column.  In other words, only if the column is omitted from the INSERT INTO query.  If a null value is supplied, that null value is used and the default is not invoked.

    In the DataTable, if no value is specified for a DataColumn when a new DataRow is created, DBNull.Value is stored in the DataColumn.  The TableAdapter's updating logic is static and submits the values stored in each DataColumn to the corresponding database column.  As a result, the SQL Server default is not invoked.

    To resolve the issue, we can remove the particular column from the InsertCommand on the generated DataAdapter.

     

    Related threads:

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/e87c0112-4c28-455b-945e-5aaa85062828
    • Marked as answer by MSDN FAQ Sunday, June 20, 2010 3:31 PM
    Sunday, June 20, 2010 3:31 PM