best way to handle sql decimal fields

Discussion in 'ASP .Net' started by Steve Richter, Mar 30, 2005.

  1. 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
    Steve Richter, Mar 30, 2005
    #1
    1. Advertising

  2. 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
    >
    >
    =?Utf-8?B?VHUtVGhhY2g=?=, Mar 31, 2005
    #2
    1. Advertising

  3. Steve Richter

    Jeremy S. Guest

    << I recommend using GetDecimal instead of GetSqlMoney >>

    Why?







    "Tu-Thach" <> wrote in message
    news:...
    > 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
    >>
    >>
    Jeremy S., Mar 31, 2005
    #3
  4. 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" <> wrote in message
    > news:...
    > > 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
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?VHUtVGhhY2g=?=, Mar 31, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ven
    Replies:
    3
    Views:
    1,306
  2. Gilbert Fine
    Replies:
    8
    Views:
    888
    Zentrader
    Aug 1, 2007
  3. Vitaliy
    Replies:
    1
    Views:
    463
    Peter Otten
    May 29, 2008
  4. valpa
    Replies:
    11
    Views:
    1,490
    Steven D'Aprano
    Mar 24, 2009
  5. spammtrapp

    Best way to handle sql-connections in webservices?

    spammtrapp, Oct 21, 2009, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    898
    CSharpner
    Nov 11, 2009
Loading...

Share This Page