[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Marisk

2/21/2002 9:24:00 PM

A puzzler :

I'm getting an invalid cast exception when accessing records using
SqlDataReader call to an ST proc as in the following code :

SqlDatareader result = command.ExecuteReader ();
while (result.Read ())
{
string s = (string) result ["somefield'];
...
}

The "somefield" is an nvarchar in the db and can be NULL.

The odd thing is that the same code runs against the same db image on a
different server and does not throw the exception. Both environments are
virtually identical, the only difference being that the data tables on the
offending machine were generated via Excel files that were exported from the
"good" machine.

I've experimented with ANSI_NULL and QUOTED_IDENTIFIER settings to no
effect.

I can fix the problem by using the Convert.IsDBNull function, but I am
mystified as to the cause of this anomaly.

Any suggestions ??


2 Answers

Zhang Weimin

2/22/2002 5:08:00 AM

0

use result.GetString() should be good.

"Marisk" <marisk@dotnetscience.com> дÈëÏûÏ¢ÐÂÎÅ
:ufRr2VxuBHA.2020@tkmsftngp02...
> A puzzler :
>
> I'm getting an invalid cast exception when accessing records using
> SqlDataReader call to an ST proc as in the following code :
>
> SqlDatareader result = command.ExecuteReader ();
> while (result.Read ())
> {
> string s = (string) result ["somefield'];
> ...
> }
>
> The "somefield" is an nvarchar in the db and can be NULL.
>
> The odd thing is that the same code runs against the same db image on a
> different server and does not throw the exception. Both environments are
> virtually identical, the only difference being that the data tables on the
> offending machine were generated via Excel files that were exported from
the
> "good" machine.
>
> I've experimented with ANSI_NULL and QUOTED_IDENTIFIER settings to no
> effect.
>
> I can fix the problem by using the Convert.IsDBNull function, but I am
> mystified as to the cause of this anomaly.
>
> Any suggestions ??
>
>


(Malcolm Stewart)

2/22/2002 5:11:00 PM

0