0

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 works well....

1
  • What is the data type of xxx? Commented May 8, 2011 at 13:33

2 Answers 2

2

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"];

Sign up to request clarification or add additional context in comments.

1 Comment

Oh. I mistyped in my code.......... Every way I tried works now... Thanks anyway.
2

Use SQLDataReader.GetDecimal method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.