I ' am copying data from table A to table B. Table B has a nullable column that has a default constraint value of 0. In general I set values of columns using the following accessor.
public object this[string columnName]
{
get { return DataTable.Rows[CurrentRow][columnName]; }
set { DataTable.Rows[CurrentRow][columnName] = value; }
}
But I do NOT set my nullable column X.
When I insert the whole row, the default value is not used. Instead of 0, NULL was inserted for the nullable column.
_sqlCommandBuilder = new SqlCommandBuilder(_sqlDataAdapter);
_sqlCommandBuilder.ConflictOption = ConflictOption.OverwriteChanges;
_sqlCommandBuilder.SetAllValues = false;
_sqlDataAdapter.Update(DataTable);
I also get the schema:
_sqlDataAdapter.Fill(DataTable);
_sqlDataAdapter.FillSchema(_dataTable, SchemaType.Mapped);
Why is ADO.NET setting NULL for my column X although I did NOT set it?
I thought that when I do not set the value of the column X, ADO.NET gets the default value from the given constraint.
Is the ADO.NET CommandBuilder able to use default constraints?