1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Conversion from Text to Integer problem in VB.NET

Discussion in 'ASP.NET' started by shyam_oec, Nov 4, 2009.

  1. shyam_oec

    shyam_oec New Member

    Dear Sir,in my VB.NET Code a runtime error is generated while i am trying to convert string value (like 20 from a TextBox ) to integer type.I tried all the possible type casting methods.plz help. below is the code.
    Dim oracon As New OracleConnection("Data Source=EARTH;Persist Security Info=True;User ID=rinku1;Password=rinku1;Unicode=True")
            Dim orains As String
            orains = "insert into user_t values(" + CInt(TextBox1.Text.ToString()) + ",'" + TextBox2.Text.ToString() + "')"
            Dim oracmd As New OracleCommand(orains, oracon)
    problem is in CInt(TextBox1.Text.ToString())..
    and the actual runtime error is--"Conversion from string "insert into user_t values(" to type 'Double' is not valid."

    I am using Oracle DataBase.and fields in database are properly defined.

    plz solve my problem
  2. nimesh

    nimesh New Member

    The problem is not in the conversion.
    The problem is coming when you are adding both the datatypes.

    As you can see in the error: Conversion from string "insert into user_t values(" to type 'Double'
    It mentions what the program is trying to convert.
    It's trying to convert "insert into user_t values(" to type 'Double', and not TextBox1.Text.ToString() to Integer.

    Conversion of TextBox1.Text.ToString() to integer is successful and when you are adding (concatenation using +) that to string "insert into user_t values(" it is failing.

    And conversion of TextBox1.Text.ToString() to integer is not required as long as pure numbers are being passed.

    You can do the validation to check if numbers are inserted or not.
    If you pass numbers without quotes, they will be taken directly into the database in the numeric datatype.

    Hope this is clear, let me know if not :D
  3. shyam_oec

    shyam_oec New Member

    thanks .its working fine.
  4. nimesh

    nimesh New Member


Share This Page