Getting a ReturnValue from cmd.Parameters in c#?
Posted
by mark smith
on Stack Overflow
See other posts from Stack Overflow
or by mark smith
Published on 2010-03-29T14:49:58Z
Indexed on
2010/03/29
15:13 UTC
Read the original article
Hit count: 247
Hi,
I have just finished converted a vb.net app to c# and one of the lines is to get @ReturnValue from the parameter.
I ended up having to CAST a lot of things..
Is there not a easier way
here is what i have
int rc = ((System.Data.SqlTypes.SqlInt32)(((System.Data.SqlClient.SqlParameter)(cmd.Parameters["@ReturnValue"])).SqlValue)).Value;
In vb.net it was as simple as doing this
Dim rc As Integer = Convert.ToInt32(cmd.Parameters("@ReturnValue").Value)
Alot easier :-)
But the problem with C# is the property Value isn't available unless I Cast to SqlParameter and i also need to cast to Sqltypes.SqlInt32 - i can't just do a standard Convert.ToInt32
© Stack Overflow or respective owner