SQL query with where clause
-
Hi friends In my SQL query I have like this Str = "ame's account" Qr= "select * from Tab where fld='" & Str & "'" Because of the 's in the where clause string its showing syntax error how to solve this Any clarification let you know, Thanks Shan
-
Hi friends In my SQL query I have like this Str = "ame's account" Qr= "select * from Tab where fld='" & Str & "'" Because of the 's in the where clause string its showing syntax error how to solve this Any clarification let you know, Thanks Shan
Shanmukeswara Rao wrote: Str = "ame's account" Qr= "select * from Tab where fld='" & Str & "'" I have had this same problem before. You should use parameters in your query. Combining the strings like this is prone to a SQL injection attack also. The way you use a parameter query depends on if you are using MS SQL or ODBC (MS Access) for your database. If you provide more information or more sample of your code I can show you better. Laterness... Doug
-
Shanmukeswara Rao wrote: Str = "ame's account" Qr= "select * from Tab where fld='" & Str & "'" I have had this same problem before. You should use parameters in your query. Combining the strings like this is prone to a SQL injection attack also. The way you use a parameter query depends on if you are using MS SQL or ODBC (MS Access) for your database. If you provide more information or more sample of your code I can show you better. Laterness... Doug
My Database is MSAccess, Earlier I used to solve once this, concatenated with ` symbol before and after the string, now it is not working. Thanks Shan
-
My Database is MSAccess, Earlier I used to solve once this, concatenated with ` symbol before and after the string, now it is not working. Thanks Shan
Str = "ame's account" Qr = "select * from Tab where fld=?" Dim cmd As OdbcCommand = New OdbcCommand(Qr, OdbcConnection1) Dim param1 as OdbcParameter = New OdbcParameter("name", OdbcType.VarChar) param1.Value = Str cmd.Parameters.Add(param1) then execute the command... Dim dr As OdbcDataReader = cmd.ExecuteReader() Laterness... Doug