Update not writing default values to the database

Hello,
 
I'm using a TableAdapter to update a table which has some default values set in SQL Server. However, every column that I leave blank gets inserted with a null value instead of the defined default value for the column.
Is there anything I am missing or is this the default behaviour
Thanks in advance for any help given.
 
Regards,
paulo


Answer this question

Update not writing default values to the database

  • Manfred Bjorlin

    Set the DefaultValue property for each defaultable DataColumn in the DataTable instance(s) affected.

    If that doesn't help, modify the INSERT and UPDATE T-SQL and add ISNULL() functions to ensure default values get written:

    UPDATE tblMyTable SET MyCol1 = ISNULL(@MyCol1, 'Default value') WHERE MyTableID = @MyTableID;

     



  • Yatin

    Hello Mike and Dennis and thank you for your replies.
     
    Working on the dataset editor, one can set the default value for each column and it works correctly. However, I'm still wondering why the DataTable wizard doesn't import the default values automatically, even if it does it for all other properties in a column. Does anyone knows why this isn't automatic
    Thanks again for the help.
     
    Regards,
    paulo

  • new2C#

    The dataset designer does not import default values. Hopefully in the next release...

    Charles

  • haroldb

    I'd like to know the answer on this question too.

    Why DataTable Wizard doesn't import the default values automatically We have many tables with amount of fields between 10 to 150 and most of them have devault values. So, what do I suppose to do Copy/Paste for each field its default value


  • johnlm

    Have you checked the ColumnMappings and verified that the columns that are mapped are being changed as you expect If they are mapped to fields, that's the likely culprit

  • acfalcon2001

    For the blank columns assign the value DBNull.Value before make an update to SQL Server. Then it will be fine.
  • vazi

    For the blank columns assign the value DBNull.Value because make an update to SQL Server. Then it will be fine.
  • Update not writing default values to the database