none
how to convert string from textbox to double data type in vb.net

    Question

  • hi all,

    i am trying to insert numeric value (from text box into sqlcommand parameter)to the numeric datatype of sql table field, but i can not and i get an error as follow:

    'convertion from string "" to type double is not valid'

    cmd.Parameters.Add("@b", SqlDbType.BigInt).Value = CDbl(TextBox34.Text)

    i dont know how to solve this problem.

    please help me,

    best regards.

    Thursday, February 20, 2014 8:00 AM

Answers

  • Rasol,

    Probably your textbox contains a blank, a non numeric character or a special characters not comma or decimal point. 

    You can use before adding the Isnumeric to test that. 

    http://msdn.microsoft.com/en-us/library/6cd3f6w1(v=vs.90).aspx

    Be aware that you should always add a value to the parameters and therefore if it is not numeric you would cancel the the command operation.

    This is one of the ways, in VB there are currently probably tens of other ways. For instance the tryparse (it was created to give C# programmers a same like IsNumeric method, it follows the rules of classic C) 

    Success
    Cor




    • Edited by Cor LigthertMVP Thursday, February 20, 2014 10:36 AM
    • Marked as answer by rasol Thursday, February 20, 2014 12:57 PM
    Thursday, February 20, 2014 8:19 AM

All replies

  • hi

    cmd.Parameters.Add("@b"SqlDbType.BigInt).Value = iif(TextBox34.Text.Trim() = "",0, CDbl(TextBox34.Text))

    Or

    cmd.Parameters.AddWithValue("@b"iif(TextBox34.Text.Trim() = "",0, CDbl(TextBox34.Text))

    All the best

    Mark as answer if you find it useful


    Shridhar J Joshi Thanks a lot

    Thursday, February 20, 2014 8:08 AM
  • Rasol,

    Probably your textbox contains a blank, a non numeric character or a special characters not comma or decimal point. 

    You can use before adding the Isnumeric to test that. 

    http://msdn.microsoft.com/en-us/library/6cd3f6w1(v=vs.90).aspx

    Be aware that you should always add a value to the parameters and therefore if it is not numeric you would cancel the the command operation.

    This is one of the ways, in VB there are currently probably tens of other ways. For instance the tryparse (it was created to give C# programmers a same like IsNumeric method, it follows the rules of classic C) 

    Success
    Cor




    • Edited by Cor LigthertMVP Thursday, February 20, 2014 10:36 AM
    • Marked as answer by rasol Thursday, February 20, 2014 12:57 PM
    Thursday, February 20, 2014 8:19 AM
  • You can try something like this:

    Double.TryParse(value, number)

    • Marked as answer by rasol Thursday, February 20, 2014 12:55 PM
    • Unmarked as answer by rasol Thursday, February 20, 2014 12:58 PM
    Thursday, February 20, 2014 9:45 AM
  • @TommyTwoTrain,

    I know this and I wrote this already, if you want to reply to the OP then use the part reply of the OP to answer. 

    Like many more experienced contributors I use threaded view and see your reply. With notification service activated I would even get an email and I'm really not interested in your reply.

    Thanks



    Cor


    Thursday, February 20, 2014 11:28 AM
  • Hi Cor,

    It gave the target, another textbox and combobox was empty, Although i had set that's default values to Zero or null. but i dot know what happens.

    you are excellent.

    thank you Cor,

    Thursday, February 20, 2014 12:55 PM
  • @TommyTwoTrain,

    I know this and I wrote this already, if you want to reply to the OP then use the part reply of the OP to answer. 

    Like many more experienced contributors I use threaded view and see your reply. With notification service activated I would even get an email and I'm really not interested in your reply.

    Thanks



    Cor



    Why dont you shove it Cor. If you dont want to read my posts then take a long walk.
    Thursday, February 20, 2014 3:46 PM