[RESOLVED] Sintax error (comma)...
When I'm trying to update or remove record from database I'm getting this error:
Code:
Syntax error (comma) in query expression 'Ime='Blagojce', Prezime='', Adresa='', Grad='', Telefonski_br='( ) -', Fax='( ) -', e_mail='''
Here is my connection string:
Code:
command.CommandText = "DELETE * FROM podatoci WHERE Ime='" & ime & "', Prezime='" & prezime & "', Adresa='" & adresa & "', Grad='" & grad & "', Telefonski_br='" & broj & "', Fax='" & fax & "', e_mail='" & email & "'"
where ime, prezime and so on are ListView selected items.
Re: Sintax error (comma)...
You have a single quote in your email field. You should either escape it with another single quote (i.e. replace single quote with 2 single quotes), or use parameterized query.
e.g.
Code:
email = email.Replace("'", "''")
command.CommandText = "DELETE * FROM podatoci WHERE Ime='" & ime & "', Prezime='" & prezime & "', Adresa='" & adresa & "', Grad='" & grad & "', Telefonski_br='" & broj & "', Fax='" & fax & "', e_mail='" & email & "'"
Re: Sintax error (comma)...
Also you encountered a problem with email doesn't rule out the rest of them. As a safety you will have to do that for all variables as I have shown in the above code for email.
Re: Sintax error (comma)...
Ummmm.... that's not the problem..... the whole where clause is wrong...
you want to delete from your table WHERE a field matches AND another field matchs AND another AND so on....
You can't use commas between fields like that in a where.... you have to use AND, or OR depending on if you want any match or all to match.
-tg
Re: Sintax error (comma)...
AAhhh... I see.
I just saw your error message and jumped to conclusion.
tg is right. You don't have the ANDs and ORs in your WHERE clause of the query.
Re: Sintax error (comma)...
I changed commas with AND clause and now it works.
Thanks to all!