Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP.NET (http://www.go4expert.com/forums/asp-net/)
-   -   Conversion from Text to Integer problem in VB.NET (http://www.go4expert.com/forums/conversion-text-integer-vbnet-t19985/)

shyam_oec 4Nov2009 23:12

Conversion from Text to Integer problem in VB.NET
 
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

nimesh 5Nov2009 12:11

Re: Conversion from Text to Integer problem in VB.NET
 
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

shyam_oec 5Nov2009 21:22

Re: Conversion from Text to Integer problem in VB.NET
 
thanks .its working fine.

nimesh 5Nov2009 21:29

Re: Conversion from Text to Integer problem in VB.NET
 
:welcome:


All times are GMT +5.5. The time now is 12:41.