Is there any difference between assigning a new DataRow value via DataRowExtensions.SetField and through an indexer by name?
1 answer
Looked at the source and it looks like the same thing as accessing through the indexer:
public static void SetField<T>(this DataRow row, string columnName, T value) { DataSetUtil.CheckArgumentNull(row, "row"); row[columnName] = (object)value ?? DBNull.Value; } With the only difference that Null is replaced with DbNull. However, what is the profit? As far as I remember, nothing prevents you from assigning an ordinary Null.
- At first it was thought that in some cases
nullmight be a completely correct non-empty value of an object-type column, and they fixed it forever in the indexer. Then they changed their minds, and the SetField extension appeared :-) - Pavel Mayorov - Ie correctly assign all the same DbNull, not Null, where not values? - iluxa1810
- When using an indexer, yes, correctly assign DbNull. Attempting to assign a null may lead to an exception if it is not an object column. - Pavel Mayorov
|