Hi

I'm trying to put the database column's value in a
variable, but when I do this I get this exception
Specified cast is not valid.

The column accept varchar values. My code is:

string reg = odrCrear.GetString("Name").ToString().Trim();

What is wrong???

Regards

Re: casting Error by Jon

Jon
Wed Nov 26 03:13:50 CST 2003

<anonymous@discussions.microsoft.com> wrote:
> I'm trying to put the database column's value in a
> variable, but when I do this I get this exception
> Specified cast is not valid.
>
> The column accept varchar values. My code is:
>
> string reg = odrCrear.GetString("Name").ToString().Trim();
>
> What is wrong???

I suggest you use GetValue and look at the type of the returned object
- just to find out what it is, for testing purposes. If the column is a
varchar, I'd expect it to be a string, but apparently it isn't.

(What are you expecting the call to ToString() to do there, by the
way?)

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too