I'm having problems converting smallint in t-sql to integer in C#.
Please can someone help me with a way round this?
Update #1
What i really trying to do is retrieve data from a column marked as smallint in sqlserver 2005 from a datareader into my application. Im sorry i'll was not really clear enough previously.
Not quite sure what problems you are having as the range of numbers in smallint is a subset of the range of integer values.
The standard convert in c# should work:
int intFromSmallInt = Convert.ToInt16(smallint);
Is the error coming from an ORM?
There is also the C# DataType "short", which is System.Int16 (a.k.a. "smallint" in SQL Server).
I prefer to use "short" just because I think it looks cooler and for no other reason.
Also, I'd use the following to pull your data (if it is nullable):
short? sVal = dr["ColName"] is System.DBNull ? null : (short?)(dr["ColName"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With