ورود

View Full Version : مشکل با جستجو در جستجو



takfanar
چهارشنبه 26 مرداد 1390, 14:55 عصر
if (CheckBox2.Checked = True) then
begin
// Bar roye jostejo haye pishin jostejo kon
end
else
begin
DataModule2.ADOQuery1.SQL.Clear;
end;
if (CheckBox1.Checked = True) then
begin
//Edit2.Text yek ' toshe
DataModule2.ADOQuery1.SQL.Add('select * from info where (' + mozo +' like ' + Edit2.Text + '%' + Trim(Edit1.Text) + '%' + Edit2.Text + ')');
end
else
begin
DataModule2.ADOQuery1.SQL.Add('select * from info where (' + mozo + '=:p0)');
DataModule2.ADOQuery1.Parameters.ParamValues['p0']:=Trim(Edit1.Text);
end;
DataModule2.ADOQuery1.Open;

به کد بالا دقت کنید یک جستجو انجام می شود که حاصلی داری بعد CheckBox2.Checked را جک دار می کنیم که sql نتاج را نگر دارد و بتوانیم بر روی نتایج جستجوی بعئی را انجام دهیم مشکل این که جواب قبلی حفط میشع بااین در باید جواب ها محدود بشن!یا هیچ جوابی نمیاد
برای مثال
select * from mytb where name=amir
100 نفر میاد با ارسال
select * from mytb where famil=alavi
باید یک نفر بیاد که نمیاد!

Vahid.Shatery
پنج شنبه 27 مرداد 1390, 00:15 صبح
سلام
این یک مثال کامل .
اگر میخوای با هر تعداد CheckBox این کار را انجام بدی بهتره که از این نمونه کد استاده کنی.


MainComponent.qryLock.Close ;
MainComponent.qryLock.SQL.Text := 'select * from tblLock where 1=1 ' ;
if chkCode.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and NumLock =' + QuotedStr (trim(edtCode.Text));
if chkClientCode.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and ClientCode =' + QuotedStr (trim(edtClientCode.Text)+'%');
if chkClientName.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and ClientName like' + QuotedStr ('%'+(edtClientName.Text) + '%');
if chkProduct.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and Product like' + QuotedStr ('%'+(edtProduct.Text)+ '%');
if chkStatus.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and Status =' + QuotedStr (trim(cbbStatus.Text));
if chkFromDate.Checked then MainComponent.qryLock.SQL.Text := MainComponent.qryLock.SQL.Text + ' and Date >=' + QuotedStr (trim(edtFromDate.Text)) + 'and Date <= ' + QuotedStr (trim(edtToDate.Text));
try
MainComponent.qryLock.Open ;
except
fmUserMsg.Show('ÏÑ ÒÇÑÔ íÑí ãÔ˜áí ÈæÌæÏ ÂãÏ . ÇØáÇÚÇÊ ÑÇãÌÏÏÇ ˜ äãÇÆíÏ . ', 'ÎØÇ', 2);
MainComponent.qryLock.SQL.Text := 'select * from qryLock' ;
end;
edtNum.Text := IntToStr(MainComponent.qryLock.RecordCount ) ;