specified cast not valid

  • Thread starter Thread starter frazer
  • Start date Start date
F

frazer

Form1.WindowState = (FormWindowState) rows[1]["AttributeValue"];

hi i get the following error when i try to do the above . why is taht?
thnx
 
frazer said:
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.
 
string
how do i cast?


Jon Skeet said:
frazer said:
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.
 
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 said:
string
how do i cast?


Jon Skeet said:
frazer said:
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.
 
frazer said:
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.
 
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.
 
frazer said:
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).
 
Back
Top