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. Advertising

  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. Advertising

  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. 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. Replies:
    12
    Views:
    609
  2. Gnarlodious
    Replies:
    4
    Views:
    17,717
    elizas
    May 5, 2010
  3. krishnakant Mane
    Replies:
    2
    Views:
    282
    Daniele Varrazzo
    May 7, 2007
  4. =?Utf-8?B?UGF1bA==?=

    Datatypes: HTTPCookie and Strings

    =?Utf-8?B?UGF1bA==?=, Nov 7, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    354
  5. Mike Gleason jr Couturier

    LINQ to SQL and new MS SQL 2008 datatypes

    Mike Gleason jr Couturier, Oct 28, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    330
    Cowboy \(Gregory A. Beamer\)
    Oct 29, 2008
Loading...

Share This Page