Jump to content

SQL help please...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Hi,

For delphi I have this query where I want to input Delphi variables. Ie
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

Edited by Jaan, 14 November 2009 - 06:10 AM.
Please use code tags when you are posting your codes !


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

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

#3
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
:S

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

Any ideas?

Thanks

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What's your actual code?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
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

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
adotable1 is not a string. Use adotable1.TableName
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
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:

Posted Image

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!!

Edited by 2710, 16 November 2009 - 01:31 PM.


#8
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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

#9
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
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.

#10
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
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 :D

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

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
For numbers, don't use single quotes around them.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog