關於Delphi的一個查詢From的編程
如題,剛入行Delphi不太久. 努力了1天.寫出如下代碼:unit Projectfrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, DBGrids, DB, ADODB, ComCtrls, StdCtrls;
type
TProjectForm = class(TForm)
lblDate: TLabel;
lblStage: TLabel;
cbStage: TComboBox;
dtpSta: TDateTimePicker;
dtpOver: TDateTimePicker;
lbl: TLabel;
dsStageDetail: TDataSource;
DBConn: TADOConnection;
qryStage: TADOQuery;
dbGirdStage: TDBGrid;
btnYes: TButton;
procedure btnYesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ProjectForm: TProjectForm;
implementation
{$R *.dfm}
procedure TProjectForm.btnYesClick(Sender: TObject);
begin
if StrToInt(cbStage.Text) in [010,020,030,110] then
begin
qryStage.Close;
qryStage.SQL.Clear;
qryStage.SQL.Add('select * from DStageDetail where Stage='''+cbStage.Text+'''');
qryStage.SQL.Add(' and outputdate >= '+formatdatetime('yyyymmdd',dtpSta.Date) );
qryStage.SQL.Add(' and ProdDate <= '+formatdatetime('yyyymmdd',dtpOver.Date) );
qryStage.Open;
end
else
begin
qryStage.Close;
qryStage.SQL.Clear;
qryStage.SQL.Add('select * from DFQCDetail where Stage='''+cbStage.Text+'''');
qryStage.SQL.Add(' and outputdate >= '+formatdatetime('yyyymmdd',dtpSta.Date) );
qryStage.SQL.Add(' and outputdate <= '+formatdatetime('yyyymmdd',dtpOver.Date) );
qryStage.Open;
end;
end
------我是分割線------
具體我真的不太知道錯誤在哪里.因為我按照.net里面if-else的理論來看,沒問題應該是,cbStage是一個下拉框.
我有試過用: cbStage.Items.text in [...] 可是結果一樣運行不出來.我覺得應該是格式問題,代碼或許有點小問題,求
好心人指點.不然我要被老板罵一死. 剛學,不懂還望老鳥多多指教