Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have an insert query in my application (vb.net 3.5; Oracle 10g)

Dim queryString As String = "insert into metadata (OBJECT_NAME, TITLE, ROW_NUM1) values ('" + strObjName + "', '" + strTitle + "', myDB.SEQ_ID.NEXTVAL)"

The title column at times have words having a apostrophe. While trying to insert these values am getting the error -

ORA-01756 quoted string not properly terminated

Can anyone tell me how to escape this?

Thank you!
Posted

You can avoid such a hassle by parameterize your sql query, refer: VB.NET: convert text with single quote to upload to Oralce DB[^]
 
Share this answer
 
v2
You can escape it by replacing the single quote by two single quotes: ''.

However, I suggest to use a parameterized query instead of escaping the string. Why? Because if you use string concatenation (like you do now) to create your command, you are not protected against SQL Injection[^]. You can use named parameters like this:
VB.NET
Dim queryString As String = "insert into metadata (OBJECT_NAME, TITLE, ROW_NUM1) values (:objName, :title, myDB.SEQ_ID.NEXTVAL)"
Dim command As OracleCommand = New OracleCommand(query, connection) ' replace connection by the name of the variable of your OracleConnection
command.CommandType = CommandType.Text
command.Parameters.Add(":objName", OracleDbType.Varchar2).Value = strObjName
command.Parameters.Add(":title", OracleDbType.Varchar2).Value = strTitle
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900