Oracle ExecuteNonQuery Error invalid character, but for other sql database system is good

Oracle SQL ExecuteNonQuery Error invalid character, but for other sql database system is good.

The code is working fine in MySql, MsSql, FirebirdSql.
And also work in Oracle SQL Plus when inserting a command like:
INSERT INTO TEST(number1,number2,string1) VALUES(1,1,'a');

Whats in oracle? Why this code errors an invalid character in ExecuteNonQuery()?
Any suggestion of the code for oracle?
Or perhaps edit the code for sure.

Honestly I hate oracle system database, but the company requires to use it.
Hmp!


Private lConStr As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=FINGER)));User Id=myuser;Password=mypassword;"       ''''''glova private variable
 
Protected lmyconn As OracleConnection   '''''gloval variable
Protected lmyComIUD As New OracleCommand ''''global variable
 
Private OpenDBs...................      ''''called during form opened.
lmyconn = New OracleConnection()
lmyconn.ConnectionString = lConStr
lmyconn.Open()
lmyComIUD.Connection = lmyconn
End Sub
 
Private sub Saving_Click...................................  ''''called when clicked
 
     Dim sqlIUD As String ''''private variable
     sqlIUD = "INSERT into test(number1,number2,string1) VALUES(?a?b?c)"
 
     lmyComIUD.Parameters.Add("?a", 2)
     lmyComIUD.Parameters.Add("?b", 2)
     myComIUD.Parameters.Add("?c", "b")
 
     lmyComIUD.CommandType = CommandType.Text
     lmyComIUD.CommandText = sqlIUD
 
     lmyComIUD.ExecuteNonQuery() '''''error invalid character. works in mysql,mssql
 
 
End Sub

Open in new window

LVL 12
rionrocAsked:
Who is Participating?
 
SujithData ArchitectCommented:
Generally bind variables are prefixed with a colon, I am not sure about the usage in .net.

Try to use colons instead of the question marks for the bind variables. Something like

sqlIUD = "INSERT into test(number1,number2,string1) VALUES(:a, :b, :c)"
     lmyComIUD.Parameters.Add(":a", 2)
     lmyComIUD.Parameters.Add(":b", 2)
     myComIUD.Parameters.Add(":c", "b")
 
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
remove the ";" at the end.
0
 
rionrocAuthor Commented:
Hello

Thanks for the quick reply.

I did not put any ;

Except this: but works fine.
And also work in Oracle SQL Plus when inserting a command like:
INSERT INTO TEST(number1,number2,string1) VALUES(1,1,'a');

But in .Net it didn't.
Please see the code.


Great is our GOD.
:)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
SujithData ArchitectCommented:
Shouldn't this statement
>> sqlIUD = "INSERT into test(number1,number2,string1) VALUES(?a?b?c)"

be like this?

sqlIUD = "INSERT into test(number1,number2,string1) VALUES(?a, ?b, ?c)"
0
 
rionrocAuthor Commented:
Hello


Thanks for that.


But its not working too.



Great is our GOD.
:)
0
 
rionrocAuthor Commented:
Hello


Thanks for that.


But its not working too.



Great is our GOD.
:)
0
 
SujithData ArchitectCommented:
Well, the add parameter portion didn't have to use the colons by the way.
Try this

sqlIUD = "INSERT into test(number1,number2,string1) VALUES(:a, :b, :c)"
     lmyComIUD.Parameters.Add("a", 2)
     lmyComIUD.Parameters.Add("b", 2)
     myComIUD.Parameters.Add("c", "b")
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
rionroc,

> But its not working too.
is a bit few feedback. some error message should be helpful.

try to help us help you!

but I think that sujith80 has got it, now...
0
 
rionrocAuthor Commented:
Ops!

>>but I think that sujith80 has got it, now...
Yes, it's working fine now.

Sorry, I did not recognize it, because some error comes out after that command:

Public Function Savedid() as integer
 
     Dim sqlIUD As String ''''private variable
     sqlIUD = "INSERT into test(number1,number2,string1) VALUES(:a,:b,:c)"
 
     lmyComIUD.Parameters.Add(":a", 2)
     lmyComIUD.Parameters.Add(":b", 2)
     myComIUD.Parameters.Add(":c", "b")
 
     lmyComIUD.CommandType = CommandType.Text
     lmyComIUD.CommandText = sqlIUD
 
     lmyComIUD.ExecuteNonQuery() '''works fine now because of : only :)


Dim did As Integer
Dim idCMD As OracleCommand = New OracleCommand("SELECT @@IDENTITY", lmyconn)
did = CInt(idCMD.ExecuteScalar()) ''''error was ORA-00936: missing expression '''
 
Return did

End Sub



Great is our GOD.
:)
0
 
SujithData ArchitectCommented:
i dont understand.
what is not working now?

if you are referring to this statement
>>Dim idCMD As OracleCommand = New OracleCommand("SELECT @@IDENTITY", lmyconn)
It is not a valid SQL statement. An sql statement should have a SELECT and FROM part for the minimum.
0
 
rionrocAuthor Commented:
Thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.