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
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