Re: CHANGING DATA TYPE
- From: "Armin Zingler" <az.nospam@xxxxxxxxxx>
- Date: Fri, 20 Jan 2006 14:50:54 +0100
"Savas Ates" <in da club> schrieb
Dim xx As SqlClient.SqlDataReader
I take values from my db by appliying that method. ?
How do you intend to handle Null values coming from the database? You can not store them in a string. Declare the variable As Object.
dim ProductPropertyValues_Value as object
ProductPropertyValues = xx("ProductPropertyValues_Value")Later, if you want to distinguish between Null and String, you have to write:
if ProductPropertyValues_Value is dbnull.value then 'handle null value else 'handle string end if
- OR -
Some people convert DBNull to Nothing in order to be able to declare the variable As String:
Dim ProductPropertyValues_Value as string dim o as object
o = xx("ProductPropertyValues_Value") if o is dbnull.value then
ProductPropertyValues_Value = Nothing
else
ProductPropertyValues_Value = o.ToString
end ifLater usage:
if ProductPropertyValues_Value is nothing then
'...
else
'...
end ifLater, if you want to save the values back to the database, you have to convert back from Nothing to DBNull.Value.
Typed datasets, or classes that you create on your own, can have typed members (As String) that simplifies this (because the member is typed), and they have additional "IsMemberNull" and "SetMemberNull" methods.
Armin
.
- Follow-Ups:
- Re: CHANGING DATA TYPE
- From: Cor Ligthert [MVP]
- Re: CHANGING DATA TYPE
- References:
- CHANGING DATA TYPE
- From: Savas Ates
- Re: CHANGING DATA TYPE
- From: Armin Zingler
- Re: CHANGING DATA TYPE
- From: Savas Ates
- CHANGING DATA TYPE
- Prev by Date: Re: Changed Date on PC, now project doesn't compile source code changes
- Next by Date: Re: sockets or tcpclient/udpclient etc..?
- Previous by thread: Re: CHANGING DATA TYPE
- Next by thread: Re: CHANGING DATA TYPE
- Index(es):
Relevant Pages
|