Last post Jul 01, 2012 05:40 PM by uick383937
Jun 30, 2012 08:33 PM|uick383937|LINK
I'm using VBnet with Access Database
I load a datatable with records that have DBNull in some fields (setting default value = "" doesn't stop this from happening on new record).
So I tediously check fields as follows:
As New LicDataSetTableAdapters.LockerTableAdapter
As New LicDataSet.LockerDataTable
lokdt = lokta.GetOnePz(0) 'gets a record
lokdr = lokdt.Rows(0)
.pzkey = ""
Catch ex As Exception
What happens is that I get an exception telling me that the field I'm testing for DBNull is DBNull.
How can I test a field for DBNull and change it to "" without throwing an exception?
Jun 30, 2012 09:21 PM|Careed|LINK
Verify that lokdr is not null/Nothing.
Jun 30, 2012 09:51 PM|uick383937|LINK
I did check that --
lokr has other fields that are showing expected values
I actually manually changed the fields from DBNull to "" in the database, and the error condition did not show up.
Thanks for the suggestion.
Jun 30, 2012 10:55 PM|Careed|LINK
In place of the IsDBNull VB function, try using either the Convert.IsDBNull or DBNull.Value.Equals method.
Jul 01, 2012 12:15 PM|uick383937|LINK
I tried both Convert.IsDBNull and DBNull.Value.Equals methods with same result --
StrongTypingException was caught.
The value for column 'pzkey' in table 'Locker' is DBNull.
InnerException: Make sure the source type is convertible to the destination type.
I closed and reloaded the IDE in case of corruption but still get this exception.
Jul 01, 2012 04:41 PM|Careed|LINK
What is the defined data type for the pzkey property?
What is the data type of the underlying column from the database table?
Jul 01, 2012 05:40 PM|uick383937|LINK
In Access the table 'Locker' has field pzkey defined as Text, Field Size 50, Default Value "", Required-No, Allow Zero Length-Yes, Indexed(Duplicates OK)
Aha -- I see that I can change the NullValue property of columns in the datatable from (Throw exception) to (Empty). This seems to convert a null valued field to "", and seems to survive a reconfigure of the table adapter, so with this setting I don't need
to check for Null at all.
Thanks for prodding me to look in the right direction.