sph3rion
asked on
Converting IsNull from VB6: operator is not valid for type 'dbnull' and type 'integer'
Hello Experts,
VB.NET newbie here...
How does this code translate correctly from VB6? -
If (Not IsNull((rs2("QTY LEFT").Value))) then
The conversion process turned the code into -
If (Not IsDBNull(rs2.Fields("QTY LEFT").Value)) then
... and that's when I get the error
VB.NET newbie here...
How does this code translate correctly from VB6? -
If (Not IsNull((rs2("QTY LEFT").Value))) then
The conversion process turned the code into -
If (Not IsDBNull(rs2.Fields("QTY LEFT").Value)) then
... and that's when I get the error
If Not(IsDBNull(rs2.Fields("[ QTY LEFT]").Value)) then
If (Not IsDBNull(rs2.Fields("[QTY LEFT]"))) then
If Not rs2.Fields("QTY LEFT").Value Is DBNull.Value Then
Have you just tried the original code:
If (Not IsNull((rs2("QTY LEFT").Value))) then
Since you are using recordsets, maybe work...
If (Not IsNull((rs2("QTY LEFT").Value))) then
Since you are using recordsets, maybe work...
ASKER
None of those are working, this is very confusing
immediate window says that the value of that field is '{system.dbnull}'
immediate window says that the value of that field is '{system.dbnull}'
well then,
If Not rs2.Fields("QTY_LEFT").Val ue Is DBNull Then
End If
or
If Not rs2.Fields("QTY_LEFT").Val ue.GetType () = GetType(DBNull) Then
End If
If Not rs2.Fields("QTY_LEFT").Val
End If
or
If Not rs2.Fields("QTY_LEFT").Val
End If
ASKER
not working either
I tried to assign the value in the field to an intTest (integer) and the compiler said I can't cast an integer as dbnull
I don't get it, .NET clearly sees that the value in the field is dbnull, yet I cannot capture that?
I tried to assign the value in the field to an intTest (integer) and the compiler said I can't cast an integer as dbnull
I don't get it, .NET clearly sees that the value in the field is dbnull, yet I cannot capture that?
hmmmm
Best Shot
Dim value As Integer
If Not (rs2.Fields("QTY_LEFT") Is DbNull) Then
value = DirectCast(rs2.Fields("QTY _LEFT"),In teger)
End If
Best Shot
Dim value As Integer
If Not (rs2.Fields("QTY_LEFT") Is DbNull) Then
value = DirectCast(rs2.Fields("QTY
End If
ASKER
I'll try that, in the meantime I'm increasing the point value
The root of the issue is that I have a table with QTY LEFT(type float) and at the very beginning of the process all values in that field in the table are NULL. I need to check for that NULL before I can enter into some code within the IF statement.
This seems like a fairly simple thing to do, it certainly is in VB6 so why is it so hard in .NET?
The root of the issue is that I have a table with QTY LEFT(type float) and at the very beginning of the process all values in that field in the table are NULL. I need to check for that NULL before I can enter into some code within the IF statement.
This seems like a fairly simple thing to do, it certainly is in VB6 so why is it so hard in .NET?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Anyone got any solutions for dealing with null values in recordsets in VB.NET?
It's not super important that I upgrade this app to .NET but I wanted to try anyway.
This type of thing happens all over this app which is just something that calculates dates automatically based on other data
It's not super important that I upgrade this app to .NET but I wanted to try anyway.
This type of thing happens all over this app which is just something that calculates dates automatically based on other data
This is the way to use it.
'DBNull.Value
If Not rs2.Fields("QTY_LEFT").Val ue Is DBNull.Value Then
End If
'DBNull.Value
If Not rs2.Fields("QTY_LEFT").Val
End If
ASKER
That was already mentioned in this question and does not work.
ASKER
I'm accepting b1xml2's answer because after some research this is how it should be done in .NET - with data tables instead of a connected recordset. Quite a change in philosophy from VB6 and I'll be educating myself on .NET when I can. For now, VB6 serves our needs best because we need to use recordsets.