i would like to insert an SQL statement from my application which writing in visual c++, but due to my insert data contain ' and " so is prompt error during inserting. So would like to know how can i insert an ' and " in MS Access database using the sql statement.Where? For what?
how if i want to enter a string with the combination of ' and "??If you are trying to instert something like O'Brian you have to double opp the quotes.
INSERT INTO tbl (name) Value ("""O'Brian""")
JR
ab'c"def
sorry, i don't understand what is parameterized queries??I recommend using parameterized queries - thereby avoiding all these thorny syntax issues.
I don't know Visual C++ but I can give you a .Net example. I assume you are using an OleDBCommand object?
cmd.CommandText = "INSERT INTO tbl (Name) Values (@Name)"
cmd.Parameters.Add("@Name", OleDbType.VarChar, 1000, "Name")
cmd.Parameters("@Name").Value = "O'Brian"
cmd.ExecuteNonQuery
OleDBconnection Cn = new OledBconnection(strConnection)
cn.OPen
OleDbcommand cmd = new OledDbCommand
cmd.Connection = cn
cmd.CommandText = SQL
cmd.Parameters.Add("@Name", OleDbType.VarChar, 1000, "Name")
cmd.Parameters("@Name").Value = "O'Brian"
cmd.ExecuteNonQuery
i'm using ADO...Doesn't VC++ have OleDB? if so, wouldn't it be something like this:
Code:OleDBconnection Cn = new OledBconnection(strConnection) cn.OPen OleDbcommand cmd = new OledDbCommand cmd.Connection = cn cmd.CommandText = SQL cmd.Parameters.Add("@Name", OleDbType.VarChar, 1000, "Name") cmd.Parameters("@Name").Value = "O'Brian" cmd.ExecuteNonQuery