I need some help - please!!
I'm taking my first foray into VB.NET, by converting a working VB6 app to .NET. The application uses a DAO recordset from an Access database; most of the fields in the table being queried are string-data, and may be empty.
All the little problems it initially encountered, I've managed to straighten out - but this one: an empty field.
Running the program in debug, I sometimes get a "Cast from type 'DBNull' to type 'String' is not valid" error message that I just can't seem to get rid of.
Researching various posts here, I've tried
and
but still get the error message on some records.
I've tried variations of the old "IsNull", "Is Not Null" and "IsEmpty", along with the tests above; I've just about gone bug-eyed trying to find something in .NET help and the books I've got available to me about null values in recordsets - and I'm still stuck.
Could someone please enlighten me? How do I test for a null-value recordset field?
I'm taking my first foray into VB.NET, by converting a working VB6 app to .NET. The application uses a DAO recordset from an Access database; most of the fields in the table being queried are string-data, and may be empty.
All the little problems it initially encountered, I've managed to straighten out - but this one: an empty field.
Running the program in debug, I sometimes get a "Cast from type 'DBNull' to type 'String' is not valid" error message that I just can't seem to get rid of.
Researching various posts here, I've tried
Code:
If .Fields("Comment").Value Is Not DBNull.Value Then
Code:
If NotNull(.Fields("Comment").Value) Then
<which is based on the following homemade function>
Private Function NotNull(ByVal prmStr As String) As Boolean
NotNull = True
If prmStr.Trim.Length = 0 Then NotNull = False
End Function
but still get the error message on some records.
I've tried variations of the old "IsNull", "Is Not Null" and "IsEmpty", along with the tests above; I've just about gone bug-eyed trying to find something in .NET help and the books I've got available to me about null values in recordsets - and I'm still stuck.
Could someone please enlighten me? How do I test for a null-value recordset field?