By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,434 Members | 2,884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,434 IT Pros & Developers. It's quick & easy.

specified cast not valid

P: n/a
Form1.WindowState = (FormWindowState) rows[1]["AttributeValue"];

hi i get the following error when i try to do the above . why is taht?
thnx
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
frazer <ic***@hotmail.com> wrote:
Form1.WindowState = (FormWindowState) rows[1]["AttributeValue"];

hi i get the following error when i try to do the above . why is taht?


Presumably because rows[1]["AttributeValue"] isn't a FormWindowState.
What is is it, actually?

Print out rows[1]["AttributeValue"].GetType() to find out.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
string
how do i cast?
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
frazer <ic***@hotmail.com> wrote:
Form1.WindowState = (FormWindowState) rows[1]["AttributeValue"];

hi i get the following error when i try to do the above . why is taht?


Presumably because rows[1]["AttributeValue"] isn't a FormWindowState.
What is is it, actually?

Print out rows[1]["AttributeValue"].GetType() to find out.

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

Nov 16 '05 #3

P: n/a
I am actually storing this in a dataset
can i store it as a Form.WindowState ? in the dataset?
or something generic like object. i tried anyType but it didnt work
thnx

"frazer" <ic***@hotmail.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
string
how do i cast?
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
frazer <ic***@hotmail.com> wrote:
Form1.WindowState = (FormWindowState) rows[1]["AttributeValue"];

hi i get the following error when i try to do the above . why is taht?


Presumably because rows[1]["AttributeValue"] isn't a FormWindowState.
What is is it, actually?

Print out rows[1]["AttributeValue"].GetType() to find out.

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


Nov 16 '05 #4

P: n/a
frazer <ic***@hotmail.com> wrote:
string
how do i cast?
You can't cast from a string to FormWindowState - although you could
use Enum.Parse to get a value.
I am actually storing this in a dataset
can i store it as a Form.WindowState ? in the dataset?
Yup.
or something generic like object. i tried anyType but it didnt work


You can put anything you like in a dataset. When you create the column,
put in the type that you're interested in - in this case,
typeof(FormWindowState).

Of course, you won't be able to put a FormWindowState into an actual
database directly - you'd need to convert to either an int
representation or a string representation.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

P: n/a
i have created my dataset manually not thru code.
and i dont see any type thats generic.
how do i store my form.windowstate ..in what datatype of the dataset.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
frazer <ic***@hotmail.com> wrote:
string
how do i cast?


You can't cast from a string to FormWindowState - although you could
use Enum.Parse to get a value.
I am actually storing this in a dataset
can i store it as a Form.WindowState ? in the dataset?


Yup.
or something generic like object. i tried anyType but it didnt work


You can put anything you like in a dataset. When you create the column,
put in the type that you're interested in - in this case,
typeof(FormWindowState).

Of course, you won't be able to put a FormWindowState into an actual
database directly - you'd need to convert to either an int
representation or a string representation.

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

Nov 16 '05 #6

P: n/a
frazer <ic***@hotmail.com> wrote:
i have created my dataset manually not thru code.
Good.
and i dont see any type thats generic.
What do you mean by that? Sorry, I don't understand.
how do i store my form.windowstate ..in what datatype of the dataset.


You can store it as FormWindowState, using typeof(FormWindowState).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.