procedure TfrmBorrow.SpeedButton1Click(Sender: TObject);
var
SQLStr,SQLAll,Log:String;
SQLTemp:Pchar;
arrstr:array[1..5]of String;
i,l:integer;
function getsth(CurrEdit:TEdit):boolean;
begin
result:=false;
if CurrEdit.Text<>'' then
result:=true;
end;
begin SQLAll:='';
SQLStr:='SELECT * FROM "BorrowRecord.db" WHERE ';
if RadioGroup1.ItemIndex=1 then Log:='OR' else Log:='AND'; if Getsth(Edit_UniNo) then
arrstr[1]:='(UniNo='''+Edit_UniNo.Text+''')';
if Getsth(Edit_BorrNo) then
arrstr[2]:='(BorrowerNo='''+Edit_BorrNo.Text+''')';
if Getsth(Edit_DateOut) then
arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')';
if Getsth(Edit_DateIn) then
arrstr[4]:='(ReturnData='''+Edit_DateIn.Text+''')';
arrstr[5]:='';
for i:=1 to 4 do
begin
arrstr[5]:=arrstr[5]+arrstr[i];
if arrstr[i]<>'' then
SQLAll:=SQLAll+Log+arrstr[i]; end;
if arrstr[5]='' then
begin
showmessage('没有查询项目?');
exit;
end; l:=strlen(Pchar(SQLAll));
GetMem(SQLTemp,l);
SQLTemp^ := Chr(0); if SQLAll[1]='O' then
StrCat(SQLTemp,Pchar(SQLAll)+2);
if SQLAll[1]='A' then
StrCat(SQLTemp,Pchar(SQLAll)+3); SQLStr:=SQLStr+SQLTemp;
FreeMem(SQLTemp);
// Application.MessageBox(Pchar(SQLStr),'预查询的SQL语句',MB_OK);
//-----------------运行到此,SQL语句是什么样的。贴出来看看。 with QueryBorrRec do
begin
SQL.Clear;
SQL.Add(SQLStr);
Prepare;
ExecSQL;
Open;
if (queryBorrRec.RecordCount<>1) then
showmessage('没有你要查找的记录,请重新输入!');
end;
end;
var
SQLStr,SQLAll,Log:String;
SQLTemp:Pchar;
arrstr:array[1..5]of String;
i,l:integer;
function getsth(CurrEdit:TEdit):boolean;
begin
result:=false;
if CurrEdit.Text<>'' then
result:=true;
end;
begin SQLAll:='';
SQLStr:='SELECT * FROM "BorrowRecord.db" WHERE ';
if RadioGroup1.ItemIndex=1 then Log:='OR' else Log:='AND'; if Getsth(Edit_UniNo) then
arrstr[1]:='(UniNo='''+Edit_UniNo.Text+''')';
if Getsth(Edit_BorrNo) then
arrstr[2]:='(BorrowerNo='''+Edit_BorrNo.Text+''')';
if Getsth(Edit_DateOut) then
arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')';
if Getsth(Edit_DateIn) then
arrstr[4]:='(ReturnData='''+Edit_DateIn.Text+''')';
arrstr[5]:='';
for i:=1 to 4 do
begin
arrstr[5]:=arrstr[5]+arrstr[i];
if arrstr[i]<>'' then
SQLAll:=SQLAll+Log+arrstr[i]; end;
if arrstr[5]='' then
begin
showmessage('没有查询项目?');
exit;
end; l:=strlen(Pchar(SQLAll));
GetMem(SQLTemp,l);
SQLTemp^ := Chr(0); if SQLAll[1]='O' then
StrCat(SQLTemp,Pchar(SQLAll)+2);
if SQLAll[1]='A' then
StrCat(SQLTemp,Pchar(SQLAll)+3); SQLStr:=SQLStr+SQLTemp;
FreeMem(SQLTemp);
// Application.MessageBox(Pchar(SQLStr),'预查询的SQL语句',MB_OK);
//-----------------运行到此,SQL语句是什么样的。贴出来看看。 with QueryBorrRec do
begin
SQL.Clear;
SQL.Add(SQLStr);
Prepare;
ExecSQL;
Open;
if (queryBorrRec.RecordCount<>1) then
showmessage('没有你要查找的记录,请重新输入!');
end;
end;
arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')';
可能有问题
改为
if Getsth(Edit_DateOut) then
arrstr[3]:='(BorrowData=+Edit_DateOut.Text+)';
试一试
arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')';
可能有问题
改为
if Getsth(Edit_DateOut) then
arrstr[3]:='(BorrowData=+Edit_DateOut.Text+)';
试一试
而在程序里面borrowdate and returndate都是string
类型肯定不匹配的
datetostr
我的意思就是日期字段应该不用加引号
arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')';
if Getsth(Edit_DateIn) then
arrstr[4]:='(ReturnData='''+Edit_DateIn.Text+''')';
这里可能要改,因为实际上你用的是字符串,建议你把BorrowData和ReturnData
写为to_char(BorrowData)和to_char(ReturnData)不过你要先看看有没有
to_char这个函数,
另外OR和AND肯定有用,用错了,结果多半不一样,
这个怎么做啊