小编Oce*_*ght的帖子

如何在delphi中的SQL(Delete)语句中包含整数值

在数据库中,DoctorID是整数列.编辑后的"//"代码行都不起作用.如果有人能告诉我如何在SQL语句中正确指定整数值,我将非常感激.

procedure TForm1.btnDeleteDocClick(Sender: TObject);
var
  iID : Integer;
begin
  iID := StrToInt (InputBox('Delete Doctor','Please enter in your Doctor ID',''));
  with dmHospital do
  begin
    qryDoctors.SQL.Clear;
    //qryDoctors.SQL.Add('DELETE FROM Doctors WHERE DoctorID = iID ' ) ;
    //qryDoctors.SQL.Add('DELETE FROM Doctors WHERE DoctorID = ' + QuotedStr(iID));
    qryDoctors.ExecSQL;
    qryDoctors.SQL.Clear;
    qryDoctors.SQL.Add('SELECT * FROM Doctors');
    qryDoctors.Open;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

sql delphi delphi-2010 sql-delete

1
推荐指数
1
解决办法
1093
查看次数

如何在 Delphi 中使用 SQL 获取值并将值设置为变量?

我试图从桌子上得到药物的价格,但我得到了:

在此处输入图片说明

procedure TForm1.BuyButtonClick(Sender: TObject);
var
  iAmount : integer;
  rRate : real;
  sMedication : string;
  sRate : string;
begin
  iAmount := 0;
  sMedication := BuyCombobox.Items[BuyCombobox.ItemIndex];
  dmHospital.qryPrices.SQL.Clear;
  dmHospital.qryPrices.SQL.Add('SELECT Price(R) FROM MedicationPrices WHERE Medication = quaotedstr(sMedication)');
  sRate := dmHospital.qryPrices.SQL;
  ShowMessage(sRate);
end;
Run Code Online (Sandbox Code Playgroud)

sql delphi ms-access delphi-2010

0
推荐指数
2
解决办法
1万
查看次数

如何使用SQL将实际值插入表中?

我正在尝试使用以下代码将值插入MedicationPrices表.

procedure TForm1.btnAddMedicineClick(Sender: TObject);
var
 sMedication, sQuantity : string;
 rPrice : real;
begin
sMedication := InputBox('Add Medication','Please enter the medications name','');
sQuantity := InputBox('Add Medication','Please enter the the quantity','');
rPrice := StrToFloat(InputBox('Add Medication','Please enter the the price',''));

with dmHospital do
begin
  qryPrices.SQL.Clear;
  qryPrices.SQL.Add('INSERT INTO MedicationPrices (Medication, Quantity)');
  qryPrices.SQL.Add('VALUES(' + QuotedStr(sMedication) +',' + QuotedStr(sQuantity)  + ' )');
  qryPrices.Parameters.ParamByName('Price').Value := rPrice;
  qryPrices.ExecSQL;
  qryPrices.SQL.Clear;
  qryPrices.SQL.Text := 'SELECT * MedicationPrices ';
  qryPrices.Open;
end;
end;
Run Code Online (Sandbox Code Playgroud)

然而,它和一些不同的变化只是不起作用.我明白了: 错误信息

我不明白为什么它没有看到"价格",因为它显然在表中. 表设计视图

sql delphi

-4
推荐指数
1
解决办法
2765
查看次数

标签 统计

delphi ×3

sql ×3

delphi-2010 ×2

ms-access ×1

sql-delete ×1