我有这个SQL查询:
如您所见,它工作正常。除了我在Delphi中使用它时。
我使用TDBLookupComboBox,TEdit和TButton。我的想法是,每当我单击TButton时,EXE就会使用DBLookupComboBox中的信息检查SQL中的表,并将结果放入TEdit中。
这是我的Delphi代码:
答案 0 :(得分:0)
在您的Delphi代码中,您使用双引号:"
您的字符串需要用单引号引起来:'
要在您的Delphi字符串中嵌入单引号,需要使用两个单引号:''
S := 'hey"there'; // hey"there
S := 'hey''there'; // hey'there
S := 'specification='''; // specification='
S := ''''; // '
答案 1 :(得分:0)
尝试此代码。
Chr(39) in delphi = " ' " sign.
我希望这会有所帮助。
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;