best way to handle sql decimal fields

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
 
G

Guest

Use Money on database side and Decimal on .NET side. I recommend using
GetDecimal instead of GetSqlMoney.
 
G

Guest

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top