procedure TForm1.Button3Click(Sender: TObject);
begin
with ADOQuery3 do
begin
close;
sql.Clear;
sql.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b';
Parameters.ParamByName('a').Value:=Listbox2.items[0];
Parameters.ParamByName('b').Value:=Listbox2.items[1];
open;
end;
end;
//Listbox3.items[listbox3.itemindex]
procedure TForm1.Button3Click(Sender: TObject);
var
I:integer;
begin
with ADOQuery3 do
begin
close;
sql.Clear;
sql.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b';
for I := 0 to ListBox2.Items.Count -1 do
if Length(ListBox2.items[I]) > 0 then
begin
Parameters.ParamByName('a').Value:=Listbox2.items[0];
Parameters.ParamByName('b').Value:=Listbox2.items[1];
open;
end
else
Parameters.ParamByName('a').Value:=edit1.Text;
Parameters.ParamByName('b').Value:=edit1.Text;
open;
end;
end;
nedeni çok basit if Length(ListBox2.items) > 0 then bu kısımda diyorsun ki listboxtaki sayı sıfırdan büyükse yap. Listboxta satır sayıları sıfırdan başla ve yükselerek devam eder. Senin ilk satırın item.indexi 0 olduğu için kodun çalışmaz. bir button koyarak showmessage(inttostr(listbox2.itemindex[0])) dersen göreceksin ki senin ilk satırdaki bilgini gösterecektir.
procedure TForm1.Button3Click(Sender: TObject);
begin
if ListBox2.Items.Count =0 then
begin
ShowMessage('Listeye Bir Bulgu Ekleyin');
end;
if ListBox2.Items.Count = 1 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Active := True;
end else
begin
if listbox2.Items.Count = 2 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Parameters.ParamByName('b').Value:=ListB ox2.Items[1];
ADOQuery3.Active := True;
end else
begin
if listbox2.Items.Count = 3 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b or bulgu_adi like :c';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Parameters.ParamByName('b').Value:=ListB ox2.Items[1];
ADOQuery3.Parameters.ParamByName('c').Value:=ListB ox2.Items[2];
ADOQuery3.Active := True;
end else
begin
if listbox2.Items.Count = 4 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b or bulgu_adi like :c or bulgu_adi like :d';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Parameters.ParamByName('b').Value:=ListB ox2.Items[1];
ADOQuery3.Parameters.ParamByName('c').Value:=ListB ox2.Items[2];
ADOQuery3.Parameters.ParamByName('d').Value:=ListB ox2.Items[3];
ADOQuery3.Active := True;
end else
begin
if listbox2.Items.Count = 5 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b or bulgu_adi like :c or bulgu_adi like :d or bulgu_adi like :e';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Parameters.ParamByName('b').Value:=ListB ox2.Items[1];
ADOQuery3.Parameters.ParamByName('c').Value:=ListB ox2.Items[2];
ADOQuery3.Parameters.ParamByName('d').Value:=ListB ox2.Items[3];
ADOQuery3.Parameters.ParamByName('e').Value:=ListB ox2.Items[4];
ADOQuery3.Active := True;
end
else
begin
if listbox2.Items.Count = 6 then
begin
ADOQuery3.Active := False;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text:='select * from tbl_sonuc where bulgu_adi like :a or bulgu_adi like :b or bulgu_adi like :c or bulgu_adi like :d or bulgu_adi like :e or bulgu_adi like :f';
ADOQuery3.Parameters.ParamByName('a').Value:=ListB ox2.Items[0];
ADOQuery3.Parameters.ParamByName('b').Value:=ListB ox2.Items[1];
ADOQuery3.Parameters.ParamByName('c').Value:=ListB ox2.Items[2];
ADOQuery3.Parameters.ParamByName('d').Value:=ListB ox2.Items[3];
ADOQuery3.Parameters.ParamByName('e').Value:=ListB ox2.Items[4];
ADOQuery3.Parameters.ParamByName('f').Value:=ListB ox2.Items[5];
ADOQuery3.Active := True;
end;
end;
end;
end;
end;
end;
end;
hocam, bir önceki kodunu şöyle bir denermisin if Length(ListBox2.items) > 0 then yerine if Length(ListBox2.items) >= 0 then olarak denermisin.
Yapmak istediğin sanırım listbox2 içindeki her satırı tbl sonuç alanında aramyıp varsa var diye uyarı vermesini sağlamak mı ?
procedure TForm1.Button1Click(Sender: TObject);
var i: word;
s: string;
begin
s:='select * from tbl_sonuc ';
if ListBox2.Items.Count>0 then
begin
s:=s+'where ';
for i := 0 to ListBox2.Items.Count-1 do
s:=s+format('bulgu_adi like "%s" or ',[listbox2.Items.Strings[i]]);
Delete(s,length(s)-2,2);
end;
adoquery3.sql.text:=s;
adoquery3.activate:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i: word;
s: string;
const tablo: string='tbl_sonuc';
alan: string='bulgu_adi';
begin
s:='select * from '+tablo;
if ListBox2.Items.Count>0 then
begin
s:=s+' where ';
for i := 0 to ListBox2.Items.Count-1 do
s:=s+format('%s like "%s*" or ',[alan,listbox2.Items.Strings[i]]);
Delete(s,length(s)-2,2);
end;
adoquery3.sql.text:=trim(s);
adoquery3.active:=true;
end;
Kodu yukarıdaki şekilde düzenleyip, kodlama içerisinde yer alan "const tablo: string='tbl_sonuc';" ve "alan: string='bulgu_adi';" kısımlarını kendi tablonuza göre uyarlayıp tekrar dener misiniz?
Son olarak aldığınız hatadaki "blablabla" kısmı tam olarak nedir?
Yukarıdaki hata dediğiniz hatada "blablabla" şeklinde ifade ettiğiniz kısımda tam olarak ne yazıyor acaba?
Kod bende düzgün çalışıyor da.
NOT: Verdiğim kodda s:=s+format('%s like "%s*" or ',[alan,listbox2.Items.Strings]);
satırını s:=s+format('%s like "%s" or ',[tablo+'.'+alan,listbox2.Items.Strings]);
Şeklinde değiştirirseniz daha sağlam olacaktır. Normalde iki türlü de çalışması lazım ama denemekten zarar gelmez.
NOT2: Verdiğim koddaki const parametrelerini kendi tablonuza göre uyarlamayı unutmayın.
"blablabla" = "baş ağrısı" veya "karın ağrısı" vs.vs. hocam yine hata verdi aynı hata acaba uygulama şeklinde buraya ekliyebilirmisiz ben sorunu bulamadım veya ben ekliyeyim uygulamayı.
Baş ağrısı, karın ağrısı gibi sorunlar pek ilgi alanıma girmiyor. =)
Sanırım bu konu beni aştı, yardımcı olamadım kusura bakmayın. Kolaylıklar dilerim, saygılarımla...
koda break point koyup, programı debug etseniz ve oluşan stringin değerini görseniz, hatayı kolay bir şekilde kendiniz çözebilirsiniz...
sanırım veritabanının ms sql server, oluşturulan sorgu stringini alın, sql server management studio da çalıştırın, olması gereken nedir, nerede hata var görebilirsiniz...