2013-04-08 49 views
1
没有默认值

我工作的程序使用if语句添加一行到SQL的另一个组合框组合框参数在德尔福

procedure TFmNewGarage.ComboBoxCountryEnter(Sender: TObject); 
begin 
    ADOQueryCountry.SQL.Clear; 
    ADOQueryCountry.SQL.Add('SELECT DISTINCT Country'); 
    ADOQueryCountry.SQL.Add(' FROM TblBaseCar'); 
    ADOQueryCountry.Open; 
    while not ADOQueryCountry.Eof do 
    begin 
    ComboBoxCountry.Items.Add(ADOQueryCountry['Country']); 
    ADOQueryCountry.Next; 
    end; 
end; 

procedure TFmNewGarage.ComboBoxCountryChange(Sender: TObject); 
begin 
    SelA:=True; 
    ComboBoxManufacturer.Show; 
    ComboBoxCountry.Hide; 
end; 

procedure TFmNewGarage.ComboBoxManufacturerEnter(Sender: TObject); 
begin 
    ADOQueryManufacturer.SQL.Clear; 
    ADOQueryManufacturer.SQL.Add('SELECT DISTINCT Manufacturer'); 
    ADOQueryManufacturer.SQL.Add(' FROM TblBaseCar'); 
    if SelA=true then 
    ADOQueryManufacturer.SQL.Add(' WHERE Country=(ComboBoxCountry.seltext)'); 
    ADOQueryManufacturer.Open; 
    while not ADOQueryManufacturer.Eof do 
    begin 
    ComboBoxManufacturer.Items.Add(ADOQueryManufacturer['Manufacturer']); 
    ADOQueryManufacturer.Next; 
    end; 
end; 

的内容在运行时,这导致错误ComboBoxCountry.seltext没有默认值,任何人都可以帮我纠正这个问题吗?

回答

1

SelText是不是你应该使用的财产。您需要为选择ItemIndex组合框Items值:

var 
Country: string; 
begin 
    ... 
    if ComboBoxCountry.ItemIndex <> -1 then 
    begin 
    Country := ComboBoxCountryItems[ComboBoxCountry.ItemIndex]; 
    ADOQueryManufacturer.SQL.Add('WHERE Country = ' + QuotedStr(Country)); 
    end; 
end; 
+0

似乎现在崩溃之前得到进一步的,但还是引发了异常的说法,例如,加拿大的参数没有默认值 – 2013-04-08 17:50:38

+0

我稍微修改我的代码;看看这个变化是否有帮助。您根本没有在代码中显示任何“参数”的用法(根据您提供的代码,您没有在任何SQL语句中使用参数化查询)。我无法解释这个问题,因为你没有提供任何与之相关的信息。我怀疑它是因为变量被添加到SQL没有引号。 – 2013-04-08 18:00:25

+0

在我的代码中没有参数的用法,它会在后面添加所有这些到数据库中,但我不确定这是否会影响它 – 2013-04-08 18:01:43