Monday, March 12, 2012

how to convert to sqltype?

For example there is a DataTable dt and the first column in the firstrow is type of string, I want to assign it to SqlString as following:

SqlString s = (SqlString)dt.Rows[0][0];

The above code throws "Invalid cast" exception. My question is how tocast it to SqlString in this case? In general, how about cast othertypes? such as if the second column in the first row is type ofdecimal, then how to cast it to SqlDecimal?

SqlDecimal d ? dt.Rows[0][1]

Thanks.

I think you could do:

SqlString s = new SqlString(dt.Rows[0][0].ToString());

I'm curious why you're wanting to work with it as a SqlString?

Marcie

Labels: , , , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home