-2

I have this SQL query:

image

As you can see, it works fine. Except when I use it in Delphi.

I use TDBLookupComboBox, TEdit, and TButton. My idea is, whenever I click on the TButton, the EXE goes to check the table in SQL using information in the DBLookupComboBox and puts the result in the TEdit.

This is my Delphi code:

image

azera
  • 3
  • 2
  • 2
    And, your question is...? http://idownvotedbecau.se/imageofcode/ http://idownvotedbecau.se/noresearch/ http://idownvotedbecau.se/unclearquestion – Remy Lebeau Sep 30 '18 at 23:26

2 Answers2

0

In your Delphi code, you are using double quotes: "

Your string needs to be enclosed in single quotes: '

To embed a single quote in your Delphi string, need to use two single quotes: ''

S := 'hey"there';        // hey"there

S := 'hey''there';       // hey'there

S := 'specification='''; // specification='

S := '''';               // '
David Dubois
  • 3,842
  • 3
  • 18
  • 36
  • like this : ADOQuery1.SQL.Add('where specification =;"'+dblookupcombobox1.text+'"'); ??? – azera Oct 01 '18 at 22:01
  • 1
    Using a parametrized query would not only make this work better, even if the user would enter a single quote in the DBLookupCombo, but it would also protect against sql injection. – GuidoG Oct 02 '18 at 15:13
0

Try this code.

Chr(39) in delphi = " ' " sign. 

I hope it will be helpful.

Begin
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('Select Sum(Cast(Total As Float)) As tot From machine Where Specification='+Chr(39)+dbLookupComboBox1.Text+Chr(39));
AdoQuery1.Open;
End;
Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
Vahid
  • 101
  • 2
  • 3