Last post Nov 11, 2009 12:27 AM by TRIMS30
Nov 10, 2009 10:06 AM|TRIMS30|LINK
Conversion from type 'DBNull' to type 'String' is not valid
from the following code
The Database is Access and Contact Field and others allow Nulls.
If null, I get the error message.
How do I work around this on any field that may contain NULL?
Nov 10, 2009 10:59 AM|Mark DotNet Evans|LINK
test to see if the value is dbnull eg.
if .item("Serial") IsNot DBNull.Value Then txtSerial.text = .item("Serial")
Nov 10, 2009 11:38 PM|TRIMS30|LINK
Thanks for your help.
I don't like to type because I make too many mistakes so will probably write function to do the work for me..
I will use something like the following
Public Function NoNull(ByVal strIn As String) As String
Dim strNull As String = ""
If Not IsDBNull(strIn) Then strNull = strIn
txtSerial.Text = NoNull(.Item("Serial"))
Nov 11, 2009 12:03 AM|Sayre|LINK
I would suggest that you change the Dim strNull as String = "" into Dim strNull as String = String.Empty
Coding Standard when you set the string into empty.
Nov 11, 2009 12:27 AM|TRIMS30|LINK
Thanks - will do!