Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: SQL help please...

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

    SQL help please...

    Hi,

    For delphi I have this query where I want to input Delphi variables. Ie
    Code:
    SELECT *
    FROM (Tablename)
    WHERE (Combobox1.text) = (Edit1.text)
    So, Im typing in something into the edit box, and choosing something from the Combobox, SQL then searches it. But its not working...Im assuming its to do with the incompatibility with the combbobox/edit box and SQL. Do I have to put some weird signs in to make it work or something?

    Thanks
    Last edited by Jaan; 11-14-2009 at 06:10 AM. Reason: Please use code tags when you are posting your codes !

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

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

    Re: SQL help please...

    myQuery.SQL.Add('SELECT * FROM '+Tablename+' WHERE '+Combobox1.text+' = '''+Edit1.text+'''');
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

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

    Re: SQL help please...

    :S

    When I enter the table name it goes 'Incompatible types: 'String' and 'TADOtable'

    Any ideas?

    Thanks

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

    Re: SQL help please...

    What's your actual code?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

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

    Re: SQL help please...

    Code:
    procedure TFrmDatabase.GoClick(Sender: TObject);
    begin
    Searchbox.Text := uppercase(searchbox.Text);
    dbgrid1.DataSource:= datasource2;
    adoquery1.SQL.add('SELECT * FROM' +adotable1+ 'WHERE '+Combobox1.text+' = '''+searchbox.text+'''');
    end;
    This part

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

    Re: SQL help please...

    adotable1 is not a string. Use adotable1.TableName
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

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

    Re: SQL help please...

    Right, I've done some messing about and this is really getting on my nerves. I think I found a glitch in my system, look at this:



    I put in 4 ' , which should give me 1 ' when it runs, but it gives me 3!!!! I am so angry. I can't believe Ive been stuck on this for like an hour. What is WRONG with this thing? I am SOO close to the finish as well, and it is refusing to cooperate!!
    Last edited by 2710; 11-16-2009 at 01:31 PM.

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

    Re: SQL help please...

    4? shouldn't it be 3?

    and do you want the search to be equal, not a LIKE search?
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

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

    Re: SQL help please...

    Um ' '' ' the outer ones represent display, and the two inner ones represent 1 apostrophe, since if you had one it would represent a 'display' apostrophe, i think.

    Um, LIKE is used for similar, I dont want that, I want it to be exactly, so = is fine.

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

    Re: SQL help please...

    Ok, I've figured out the problem. It's because the field GiftAidID is set as Number in the database, so the string and integer becomes incompatible. So I set it as text in the database and it now works, however, the error still comes up for AmountRaised even if I have set it as a Text.

    I'll play around with it.

    Thanks for help guys

    EDIT: Omg, I dunno what I done, but now it works, yippee lol

Closed Thread
Page 1 of 2 12 LastLast

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