DBNull Problem

  • Thread starter Thread starter tma
  • Start date Start date
T

tma

I have an untyped Dataset I'm reading in from Excel and writing to a
..NewDataRow.

My problem is that some of the cells in Excel are empty and writing those
cells to the datarow cause a DBNull error. Here's my code:

drInventoryItem = dsInv.Inventory.NewInventoryRow

drInventoryItem.ItemCat2ID =
dsImportInventory.Tables(0).Rows(x).Item("Category2")



Any thoughts on how to overcome this?
 
If IsDBNulldsImportInventory.Tables(0).Rows(x).Item("Category2")) Then
drInventoryItem.ItemCat2ID = DBNull.Value
Else
drInventoryItem.ItemCat2ID =
dsImportInventory.Tables(0).Rows(x).Item("Category2")
End If
 
"How?" is my question...

How do I check to see if
"dsImportInventory.Tables(0).Rows(x).Item("Category2")" is null?
 
Correction:

If IsDBNull(dsImportInventory.Tables(0).Rows(x).Item("Category2")) Then
drInventoryItem.ItemCat2ID = DBNull.Value
Else
drInventoryItem.ItemCat2ID =
dsImportInventory.Tables(0).Rows(x).Item("Category2")
End If
 
What I've found is a variation of your suggestion and it's this:

If dsImportInventory.Tables(0).Rows(x).IsNull("Category2"))

That seems to work and I'm grateful for your help.
 
Back
Top