Results 1 to 6 of 6

Thread: [RESOLVED] Sintax error (comma)...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Resolved [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.

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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 & "'"
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Sintax error (comma)...

    I changed commas with AND clause and now it works.
    Thanks to all!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width