I want to read a number of type decimal(8,2)
from a SQL Server database, and store them in an object, MyRow
.
public class MyRow
{
public decimal data1 { get; set; }
}
...
List<MyRow> values = new List<MyRow>();
SqlDataReader reader = command.ExecuteReader();
while (reader.read())
{
values.Add( new MyRow() {
data1 = decimal.Parse(((double)reader["data1"]).ToString("R"))
}
}
This solution seems far from ideal, and it seems like I'm doing too much conversion for something that seems like it would be fairly simple. Since the values for data
are already decimal(8,2)
in the database, is there any way to read the data into a decimal
type without the conversion from an object
to a decimal
?