开发者

ASP.net/C# SqlDataReader and Decimal problem

I am trying to use SqlDataReader to read a Decimal(10,2) from a MSSQL database into a formatted string like 8.80.

SqlDataReader reader = cmd.ExecuteReader();
xxx =  reader["xxx"] //???

I tried several ways but always got 8.00 instead of 8.80. And I can confirm the data in database is 8.80.

Could anyone tell me how to do this? Thanks.

Edit: Thanks for your time. It turns out that I mistype in my code. Every way I tried actually wor开发者_如何学Pythonks well....


reader["xxx"] is returning an object. If you are sure this column is a decimal then cast it to decimal decimal xxx = (Decimal)reader["xxx"];


Use SQLDataReader.GetDecimal method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜