The way I know it's deffintely DBNull is when I use String.IsNullOrEmpty it errors out with 'Cant convert type DBNull to type String'
I'm using an ODBCDataReader with the following ODBCCommand to transfer from a Quickbooks Desktop company file to a SQL database via LINQ; not sure if this is a quirk of ODBC or something as this is the first time I've used it:
SELECT id, string0, string1, string2, string3, int FROM Table1 WHERE (IsActive = 1)
To process the result I'm using:
IIf(IsDBNull(e(3)) Or IsNothing(e(3)), String.Empty, e(3))
The table I'm transfering to does not allow NULLs.
I've tried using Not and swapping the resulting options around, I've tried using Is Nothing and DBNull.Value.Equals() and of course, IsNullOrEmpty. When I don't have IsNullOrEmpty in the statement I get a 'Cannot insert NULL into Table' I've also tried swapping Or with OrElse. As mentioned below I should be using OrElse anyway.
Now, with another table in the same company file this code works perfectly with DBNulls. I copied the code directly and I've tried every combination of things I can think of. What could possibly be wrong with this instance that would cause it to not recognize the field type?
If you can point me in the right direction, I'd greatly appreciate it.
What has tripped you up is that the
Orin VB.NET is base don the one in VB6, which did not short-circuit the logic:https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/orelse-operator
Try this instead: