best way to handle sql decimal fields

  • Thread starter Thread starter Steve Richter
  • Start date Start date
S

Steve Richter

I have having a hard time getting the numeric columns in my sql tables
to map correctly to .NET. I have a price and a cost column in a
table. What is the most .NET friendly way to declare those columns?

cmd = new SqlCommand("CREATE TABLE ItemMaster ( " +
"ItemId INT PRIMARY KEY," +
"ItemDesc varChar(80), " +
"Price Numeric(7,2), " +
"Cost Numeric(7,2)",
conn);

new SqlParameter( "@Price", SqlDbType.Money ) ; // ??????

System.Decimal cost ;
SqlDataReader reader ;
cost = reader.GetSqlMoney(3) ; // ?????????????????

thanks,
-Steve
 
Use Money on database side and Decimal on .NET side. I recommend using
GetDecimal instead of GetSqlMoney.
 
GetSqlMoney is specific to SqlDataReader. GetDecimal is in the IDataRecord
interface. If you are planning to abstract your database access, then you
don't want to make calls that are specific to any particular provider.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top