DBNull Problem

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?
 
S

Scott M.

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
 
T

tma

"How?" is my question...

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

Scott M.

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
 
T

tma

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top