I have following query and face error and i am Using XE8 with MS Access
我有以下查询和面部错误,我正在使用XE8与MS Access
Syntax error. in query expression 'select CCarID from tblcar where Car = (LX008)'
语法错误。在查询表达式'从tblcar中选择CCarID,其中Car =(LX008)'
Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tblcaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('values (select CCarID from tblcar where Car = ('+ComboBox2.Text+'))');
adoQueryCCA.SQL.Add('VALUES(:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('Done');
end;
Update:
procedure TFNewCarAct.FromShow(Sender: TObject);
begin
ADOQueryCT.Open;
while Not ADOQueryCT.Eof do
begin
ComboBox1.Items.Add(ADOQueryCT.FieldByName('Name').AsString);
ADOQueryCT.Next;
end;
ADOQueryCT.Close;
if ComboBox1.Items.Count > 0 then ComboBox1.ItemIndex := 0;
end;
procedure TFNewCarAct.OnComboBox1Change(Sender: TObject);
begin
ComboBox2.Items.BeginUpdate;
try
ComboBox2.Clear;
ADOQueryCC.Parameters.ParamByName('Name').Value := ComboBox1.Text;
ADOQueryCC.Open;
while Not ADOQueryCC.Eof do
begin
ComboBox2.Items.AddObject(ADOQueryCC.FieldByName('Car').AsString, '');
ADOQueryCC.Next;
end;
ADOQueryCC.Close;
if ComboBox2.Items.Count > 0 then ComboBox2.ItemIndex := 0;
finally
ComboBox2.Items.EndUpdate;
end;
end;
The Car in the comboBox2 acquire from the tblecar and want to save the FK in the tblcaractivity table.
comboBox2中的Car从tblecar获取并希望将FK保存在tblcaractivity表中。
The suggestion provides by the Victoria now cause "Unspecified error".
维多利亚州提出的建议现在导致“未指明的错误”。
Can you help how i modify my code to save FK in tblcaractivity table.
你能帮助我修改我的代码以便在tblcaractivity表中保存FK吗?
1 个解决方案
#1
0
Give a try;
试一下;
Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tblcaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('VALUES(:CCarID,:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('CCarID').Value:= Integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('Done');
end;
procedure TFNewCarAct.FromShow(Sender: TObject);
begin
ADOQueryCT.Open;
while Not ADOQueryCT.Eof do
begin
ComboBox1.Items.Add(ADOQueryCT.FieldByName('Name').AsString);
ADOQueryCT.Next;
end;
ADOQueryCT.Close;
if ComboBox1.Items.Count > 0 then ComboBox1.ItemIndex := 0;
end;
procedure TFNewCarAct.OnComboBox1Change(Sender: TObject);
begin
ComboBox2.Items.BeginUpdate;
try
ComboBox2.Clear;
ADOQueryCC.Parameters.ParamByName('Name').Value := ComboBox1.Text;
ADOQueryCC.Open;
while Not ADOQueryCC.Eof do
begin
ComboBox2.Items.AddObject(ADOQueryCC.FieldByName('Car').AsString, TObject(ADOQueryCC.FieldByName('CCarID').AsInteger));
ADOQueryCC.Next;
end;
ADOQueryCC.Close;
if ComboBox2.Items.Count > 0 then ComboBox2.ItemIndex := 0;
finally
ComboBox2.Items.EndUpdate;
end;
end;
#1
0
Give a try;
试一下;
Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tblcaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('VALUES(:CCarID,:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('CCarID').Value:= Integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('Done');
end;
procedure TFNewCarAct.FromShow(Sender: TObject);
begin
ADOQueryCT.Open;
while Not ADOQueryCT.Eof do
begin
ComboBox1.Items.Add(ADOQueryCT.FieldByName('Name').AsString);
ADOQueryCT.Next;
end;
ADOQueryCT.Close;
if ComboBox1.Items.Count > 0 then ComboBox1.ItemIndex := 0;
end;
procedure TFNewCarAct.OnComboBox1Change(Sender: TObject);
begin
ComboBox2.Items.BeginUpdate;
try
ComboBox2.Clear;
ADOQueryCC.Parameters.ParamByName('Name').Value := ComboBox1.Text;
ADOQueryCC.Open;
while Not ADOQueryCC.Eof do
begin
ComboBox2.Items.AddObject(ADOQueryCC.FieldByName('Car').AsString, TObject(ADOQueryCC.FieldByName('CCarID').AsInteger));
ADOQueryCC.Next;
end;
ADOQueryCC.Close;
if ComboBox2.Items.Count > 0 then ComboBox2.ItemIndex := 0;
finally
ComboBox2.Items.EndUpdate;
end;
end;