473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

best way to handle sql decimal fields

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

Nov 19 '05 #1
3 3657
Use Money on database side and Decimal on .NET side. I recommend using
GetDecimal instead of GetSqlMoney.

"Steve Richter" wrote:
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

Nov 19 '05 #2
<< I recommend using GetDecimal instead of GetSqlMoney >>

Why?



"Tu-Thach" <Tu*****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Use Money on database side and Decimal on .NET side. I recommend using
GetDecimal instead of GetSqlMoney.

"Steve Richter" wrote:
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

Nov 19 '05 #3
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.

"Jeremy S." wrote:
<< I recommend using GetDecimal instead of GetSqlMoney >>

Why?



"Tu-Thach" <Tu*****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Use Money on database side and Decimal on .NET side. I recommend using
GetDecimal instead of GetSqlMoney.

"Steve Richter" wrote:
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


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
16
by: PeteCresswell | last post by:
I was happily coding along, putting some calculation results (rolling annualized rates of return - too compute-intensive to calculate on-the-fly - had tb staged beforehand via a batch job) into...
2
by: David Nunn | last post by:
Need to preface that I am not much of an Access type. Doing I have several tables that have currency fields, which I run queries against to compare the figures in both. The data is imported from...
3
by: Amaryllis | last post by:
Hi again, I'm new to the world of communicating between VB.NET and AS/400, so I've been posting a lot of questions lately since no one else in the company has done anything like this before. ...
5
by: Patrick Sullivan | last post by:
I was having hell trying to get values like 6.50 to return two ints, a = 6 and b = 50. The data is from a program that uses nn.nn for a time format in hours and minutes. But 6.50 in decimal would...
1
by: skhuon | last post by:
Hi, when I divide Sum (AMT_NET_GAAP_GNLS)/Sum (AMT_UPB_FM) and these two fields are decimal fields, the results is 0 I know there is a way to cast the decimal point but i keep on getting errors,...
3
by: Bill Fuller | last post by:
Here is the scenario. We will be writing a web application that will need to sometimes properly handle sensitive data (salary, ssn, profit, etc.) using roles. This data will be restricted at a...
16
by: tshad | last post by:
I have a string field and a decimal fields and was wondering what the best way to check for numeric is? I have to do something like: If (myAmount is numeric) { total += myAmount; }
9
muaddubby
by: muaddubby | last post by:
Hi I'm running into a scenario with a DataSet that has a schema loaded into it, tries to then load data (that matches the schema), and fails with a "Input string was not in a correct format"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.