Error with converting string to double


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Error with converting string to double

  1. #1
    Join Date
    Jul 2004
    Posts
    365

    Question Error with converting string to double

    Hello all,

    I'm using ASP.Net and I'm doing the following:

    object.Amount = CDbl(txtAmount.text)

    When txtAmount.text = "", (no value entered into it) I get the following error:

    System.InvalidCastException: Cast from string "" to type 'Double' is not valid.

    How do I fix this without defualting the textbox to 0?

    Thanks..

    Jim

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try using Val or Double.TryParse instead of CDbl, or add a RequiredFieldValidator to the field.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jun 2004
    Posts
    93
    Or catch the error and handle it.

Similar Threads

  1. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 11:18 AM
  2. Replies: 3
    Last Post: 10-02-2005, 11:57 PM
  3. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 02:32 PM
  4. Replies: 1
    Last Post: 06-05-2001, 06:12 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center