text box and SqlDecimal datatypes

Discussion in 'ASP .Net' started by Mark, Nov 7, 2005.

  1. Mark

    Mark Guest

    Hi all, I have a DAL which takes in a value as shown below ready for my
    MSSQL stored procedure.

    protected SqlDecimal _annualLeave = SqlDecimal.Null;
    public SqlDecimal AnnualLeave
    {

    get {return _annualLeave;}

    set{ _annualLeave = value;}

    }

    I have a problem where when I try to pass in information from a textbox on a
    ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!

    I thought I could just go..

    ((System.Data.SqlDecimal)AnnualLeave.Text)

    Where AnnualLeave.Text is the value of my textbox on my form, but I received
    "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
    (Which is fair enough)

    So, I tried

    ((System.Data.SqlDecimal)(Convert.ToDecimal(AnnualLeave.Text))

    but for some reason, this rounds the number to an integer!! e.g. 12.2
    becomes 12!!!!!

    Can someone please tell me what am I doing wrong here, it's been a long day
    :p

    Thanks
    Mark
     
    Mark, Nov 7, 2005
    #1
    1. Advertisements

  2. Mark

    Onin Tayson Guest

    Hi Mark,

    just use Convert.ToDecimal(AnnualLeave.Text)

    HTH,

    "Mark" <> wrote in message
    news:...
    > Hi all, I have a DAL which takes in a value as shown below ready for my
    > MSSQL stored procedure.
    >
    > protected SqlDecimal _annualLeave = SqlDecimal.Null;
    > public SqlDecimal AnnualLeave
    > {
    >
    > get {return _annualLeave;}
    >
    > set{ _annualLeave = value;}
    >
    > }
    >
    > I have a problem where when I try to pass in information from a textbox on
    > a
    > ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
    >
    > I thought I could just go..
    >
    > ((System.Data.SqlDecimal)AnnualLeave.Text)
    >
    > Where AnnualLeave.Text is the value of my textbox on my form, but I
    > received
    > "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
    > (Which is fair enough)
    >
    > So, I tried
    >
    > ((System.Data.SqlDecimal)(Convert.ToDecimal(AnnualLeave.Text))
    >
    > but for some reason, this rounds the number to an integer!! e.g. 12.2
    > becomes 12!!!!!
    >
    > Can someone please tell me what am I doing wrong here, it's been a long
    > day
    > :p
    >
    > Thanks
    > Mark
    >
    >
     
    Onin Tayson, Nov 7, 2005
    #2
    1. Advertisements

  3. Mark

    Mark Guest

    Hi Onin, I was actually doing this originally and still get the same
    problem.

    Thanks for your advice
    Cheers
    Mark
    "Onin Tayson" <> wrote in message
    news:O%...
    >
    > Hi Mark,
    >
    > just use Convert.ToDecimal(AnnualLeave.Text)
    >
    > HTH,
    >
    > "Mark" <> wrote in message
    > news:...
    > > Hi all, I have a DAL which takes in a value as shown below ready for my
    > > MSSQL stored procedure.
    > >
    > > protected SqlDecimal _annualLeave = SqlDecimal.Null;
    > > public SqlDecimal AnnualLeave
    > > {
    > >
    > > get {return _annualLeave;}
    > >
    > > set{ _annualLeave = value;}
    > >
    > > }
    > >
    > > I have a problem where when I try to pass in information from a textbox

    on
    > > a
    > > ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
    > >
    > > I thought I could just go..
    > >
    > > ((System.Data.SqlDecimal)AnnualLeave.Text)
    > >
    > > Where AnnualLeave.Text is the value of my textbox on my form, but I
    > > received
    > > "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
    > > (Which is fair enough)
    > >
    > > So, I tried
    > >
    > > ((System.Data.SqlDecimal)(Convert.ToDecimal(AnnualLeave.Text))
    > >
    > > but for some reason, this rounds the number to an integer!! e.g. 12.2
    > > becomes 12!!!!!
    > >
    > > Can someone please tell me what am I doing wrong here, it's been a long
    > > day
    > > :p
    > >
    > > Thanks
    > > Mark
    > >
    > >

    >
    >
     
    Mark, Nov 7, 2005
    #3
    1. Advertisements

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. Replies:
    1
    Views:
    1,359
    David Wier
    Aug 5, 2005
  2. Neelu
    Replies:
    1
    Views:
    702
    TechBookReport
    Jan 10, 2006
  3. Gnarlodious
    Replies:
    4
    Views:
    17,991
    elizas
    May 5, 2010
  4. cjl
    Replies:
    1
    Views:
    10,714
    Michael Winter
    Oct 31, 2005
  5. Mike

    Combo Box and text box

    Mike, Sep 24, 2003, in forum: Javascript
    Replies:
    2
    Views:
    404
  6. Mike

    combo box with Text box

    Mike, Sep 24, 2003, in forum: Javascript
    Replies:
    0
    Views:
    192
  7. Jim

    Check box and text box disable

    Jim, Jun 3, 2004, in forum: Javascript
    Replies:
    3
    Views:
    283
    Randy Webb
    Jun 4, 2004
  8. cjl
    Replies:
    7
    Views:
    414
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
Loading...