Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > best way to handle sql decimal fields

Reply
Thread Tools

best way to handle sql decimal fields

 
 
Steve Richter
Guest
Posts: n/a
 
      03-30-2005
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VHUtVGhhY2g=?=
Guest
Posts: n/a
 
      03-30-2005
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
>
>

 
Reply With Quote
 
 
 
 
Jeremy S.
Guest
Posts: n/a
 
      03-31-2005
<< I recommend using GetDecimal instead of GetSqlMoney >>

Why?







"Tu-Thach" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>>
>>



 
Reply With Quote
 
=?Utf-8?B?VHUtVGhhY2g=?=
Guest
Posts: n/a
 
      03-31-2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to handle sql-connections in webservices? spammtrapp ASP .Net Web Services 2 11-11-2009 07:50 PM
how to convert from Decimal('1.23456789') to Decimal('1.234') valpa Python 11 03-24-2009 07:11 AM
Error: Cannot convert Decimal("0.0000") to Decimal Vitaliy Python 1 05-29-2008 10:36 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM



Advertisments