1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    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.
    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)
            oracon.Open()
            oracmd.ExecuteNonQuery()
            oracon.Close()
    
    
    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

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    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

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    thanks .its working fine.
     
  4. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    :welcome:
     

Share This Page