Closed Thread
Results 1 to 10 of 10

Thread: Oh god, more SQL ¬__¬

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Oh god, more SQL ¬__¬

    Hi,

    so I effectively have this code:

    Insert into GiftAid
    (GiftAidID,Surname, Title, PostCode)
    values (22,'q','MR', 'q');

    and depending on whether I put quotes around 'GiftAid' (my table name) I get different errors:




    woops posted the same picture, well the other says:

    Syntax error in query. Incomplete query clause.

    I have tried so many different ways of adding apostrophe here, adding sqaure brackets etc that I have almost given up. Why does SQL have to be so awkward >__>

    Any help appreciated (wingedpanther )

    Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Oh god, more SQL ¬__¬

    I don't see anything wrong with your query. What does your Pascal/Delphi code around it look like? The code that executes the query... Are you using TAdoDataSet?

  4. #3
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Oh god, more SQL ¬__¬

    When doing an insert, you use the ExecSQL method instead of the Open method.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Oh god, more SQL ¬__¬

    Ok, so now look at my code:

    Code:
    adoquery2.SQL.Clear;
    adoquery2.SQL.Add('Insert into "GiftAid"');
    adoquery2.SQL.Add('(GiftAidID, Title, Initial, Surname, Address, PostCode, E-Mail, DateR)');
    adoquery2.SQL.Add('values');
    adoquery2.SQL.Add('(' + ''''+Spinedit1.Text+''''  + ',' + ''''+combobox1.Text+'''' + ',' + '''' +Combobox2.Text+ '''' + ',' + ''''+Edit1.Text+'''' + ',' + ''''+Edit2.Text+'''' + ',' + ''''+Edit3.Text+'''' + ',' + ''''+Edit4.Text+'''' + ',' + ''''+Edit5.Text+'''' + ');');
    adoquery2.execsql
    But it still doesn't work.I keep getting an error message. Syntax error in query. Incomplete Query clause.



    @Jordan, yes, I am using a dataset..i think. I have a Adoquery, and a Datasource which is linked to the query through dataset

    EDIT: Is it something to do with putting my tablename in quotes? But if I dont, I get an 'INSERT INTO' error, but on most examples, they dont have quotes.

    EDIT: Can it be something to do with 2007 Access' protection thingy?Well, Ima go to sleep now, so Ill figure it in the morning
    Last edited by 2710; 11-17-2009 at 03:25 PM.

  6. #5
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Oh god, more SQL ¬__¬

    When debugging SQL, I tend to either add a showmessage (like below) or log the failed SQL to file using a try/except. What SQL is it generating?
    Code:
    adoquery2.SQL.Clear;
    adoquery2.SQL.Add('Insert into "GiftAid"');
    adoquery2.SQL.Add('(GiftAidID, Title, Initial, Surname, Address, PostCode, E-Mail, DateR)');
    adoquery2.SQL.Add('values');
    adoquery2.SQL.Add('(' + ''''+Spinedit1.Text+''''  + ',' + ''''+combobox1.Text+'''' + ',' + '''' +Combobox2.Text+ '''' + ',' + ''''+Edit1.Text+'''' + ',' + ''''+Edit2.Text+'''' + ',' + ''''+Edit3.Text+'''' + ',' + ''''+Edit4.Text+'''' + ',' + ''''+Edit5.Text+'''' + ');');
    showmessage(adoquery2.SQL.text);
    adoquery2.execsql
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #6
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Oh god, more SQL ¬__¬

    Here ya go:



    Hmm, I still don't see where the mistake is. I put the number in quotes because it is stored as a text in the database. Even if I don't put in a quote, it still gives an error. Hmm...

    Here is the error:


  8. #7
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Oh god, more SQL ¬__¬

    Depending on the type of database, you may have to exclude the ; at the end of your statement, or not put single quotes around your table name. Can you play around with the SQL syntax using a different tool?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #8
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Oh god, more SQL ¬__¬

    YESSSS! I figured it out after about an hour. GAWD!

    The problem was the column 'E-mail'. For some reason, SQL doesn't like the hypen (-) sign and therefore gives an error. I just changed it to Email and voila! Well I guess its good that this happened, since now I will learn from it, but also, for SUCH a little problem !!!!!! Lol

    Thanks guys!

  10. #9
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Oh god, more SQL ¬__¬

    yeah. play safe, just use a-z and no reserved words as field names, and it will work good...
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  11. #10
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Oh god, more SQL ¬__¬

    Underscores also usually work well for field/table names.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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