I am assigning one datarow object the values of another datarow object. For example:
newAddress.AddrId = frenchAddress.AddrId
newAddress.AddrLn1 = frenchAddress.AddrLn1
newAddress.AddrLn2 = frenchAddress.AddrLn2
newAddress.AddrLn3 = frenchAddress.AddrLn3
newAddress.AddrCityNm = frenchAddress.AddrCityNm
newAddress.CntryId = frenchAddress.CntryId
newAddress.ProvId = frenchAddress.ProvId
Some of the values in frenchAddress can be NULL so I end up getting an exception because I am assigning newAddress the value of DBNull. What is the best and cleanest way of handling DBNull? Is there anyway to just insert NULL where there is a DBNull?
Using VB.Net.
Since that is a typed
DataRow(so an auto-generated type with named properties) there are already methods for this purpose:If it was not a typed but a standard
DataRowyou could use theSetFieldmethod that supports nullable types and also should handle this case: