Home All Groups Group Topic Archive Search About
Author
20 Jan 2006 1:21 PM
Savas Ates
Dim ProductPropertyValues_Value as string



ProductPropertyValues_Value = xx("ProductPropertyValues_Value")

it returns error.. Because  xx("ProductPropertyValues_Value") returns NULL
or "" records?

How can i convert it to string or  which method should i use it ?

Author
20 Jan 2006 1:33 PM
Armin Zingler
"Savas Ates" <in da club> schrieb
> Dim ProductPropertyValues_Value as string
>
>
>
> ProductPropertyValues_Value = xx("ProductPropertyValues_Value")
>
> it returns error.. Because  xx("ProductPropertyValues_Value")
> returns NULL or "" records?
>
> How can i convert it to string or  which method should i use it ?


Did you enable Option Strict?

What is xx("ProductPropertyValues_Value")?

What is the type of xx("ProductPropertyValues_Value")?

What is the instance type of the object returned by
xx("ProductPropertyValues_Value")?


Armin
Author
20 Jan 2006 1:35 PM
Savas Ates
Dim xx As SqlClient.SqlDataReader

I take values from my db by appliying that method. ?



"Armin Zingler" <az.nospam@freenet.de>, haber iletisinde þunlarý
yazdý:e%23YBbYcHGHA.2***@TK2MSFTNGP15.phx.gbl...
Show quoteHide quote
> "Savas Ates" <in da club> schrieb
>> Dim ProductPropertyValues_Value as string
>>
>>
>>
>> ProductPropertyValues_Value = xx("ProductPropertyValues_Value")
>>
>> it returns error.. Because  xx("ProductPropertyValues_Value")
>> returns NULL or "" records?
>>
>> How can i convert it to string or  which method should i use it ?
>
>
> Did you enable Option Strict?
>
> What is xx("ProductPropertyValues_Value")?
>
> What is the type of xx("ProductPropertyValues_Value")?
>
> What is the instance type of the object returned by
> xx("ProductPropertyValues_Value")?
>
>
> Armin
>
Author
20 Jan 2006 1:50 PM
Armin Zingler
"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 if

Later usage:
    if ProductPropertyValues_Value is nothing then
        '...
    else
        '...
    end if

Later, 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
Author
20 Jan 2006 3:55 PM
Cor Ligthert [MVP]
Armin,

Do I see something wrong

ToString or Cstr does mostly everything in these cases.

However because all these answers I become confused.

Cor
Author
20 Jan 2006 4:06 PM
Armin Zingler
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb
> Armin,
>
> Do I see something wrong
>
> ToString or Cstr does mostly everything in these cases.
>
> However because all these answers I become confused.
>
> Cor


DBNull.Tostring probably gives not the result expected.


Armin
Author
20 Jan 2006 3:05 PM
Herfried K. Wagner [MVP]
"Savas Ates" <in da club> schrieb:
> Dim ProductPropertyValues_Value as string
>
> ProductPropertyValues_Value = xx("ProductPropertyValues_Value")
>
> it returns error.. Because  xx("ProductPropertyValues_Value") returns NULL
> or "" records?
>
> How can i convert it to string or  which method should i use it ?

\\\
Dim Value As Object = xx("...")

' 'If Value Is DBNull.Value Then...'.
If IsDBNull(Value) Then
    s = ""
Else
    s = DirectCast(Value, String)
End If
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Jan 2006 3:28 PM
Armin Zingler
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb
> Dim Value As Object = xx("...")
>
> ' 'If Value Is DBNull.Value Then...'.
> If IsDBNull(Value) Then
>    s = ""

This means, you can not distinguish between Null and "" anymore, later. I
guess this is not intended because if both were equal, the database design
would be wrong (usually).


Armin
Author
20 Jan 2006 3:48 PM
Herfried K. Wagner [MVP]
"Armin Zingler" <az.nospam@freenet.de> schrieb:
>> Dim Value As Object = xx("...")
>>
>> ' 'If Value Is DBNull.Value Then...'.
>> If IsDBNull(Value) Then
>>    s = ""
>
> This means, you can not distinguish between Null and "" anymore, later. I
> guess this is not intended because if both were equal, the database design
> would be wrong (usually).

This depends on what you want to archive.  If the intention is to display
the values in labels or similar, then my code makes sense, IMO.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Jan 2006 4:05 PM
Armin Zingler
Show quote Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb
> "Armin Zingler" <az.nospam@freenet.de> schrieb:
> > > Dim Value As Object = xx("...")
> > >
> > > ' 'If Value Is DBNull.Value Then...'.
> > > If IsDBNull(Value) Then
> > >    s = ""
> >
> > This means, you can not distinguish between Null and "" anymore,
> > later. I guess this is not intended because if both were equal,
> > the database design would be wrong (usually).
>
> This depends on what you want to archive.  If the intention is to
> display the values in labels or similar, then my code makes sense,
> IMO.


As from the OP's post I only see a String typed variable, I can not assume
that a label will be used. I can only answer based on the information I
have. That's why I also assume the correct database design. Consequently, it
does not make sense to convert Null to "". But let's wait for the OP's
answer.


Armin