
Coding :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, ComCtrls, Grids, DBGrids, ExtCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Qtable: TADODataSet;
QField: TADODataSet;
Edit1: TEdit;
Button1: TButton;
QtableName: TWideStringField;
Qtableobject_id: TIntegerField;
QFieldname: TWideStringField;
QFieldobject_id: TIntegerField;
QCari: TADODataSet;
ListBox1: TListBox;
Label1: TLabel;
Button2: TButton;
Animate1: TAnimate;
Label2: TLabel;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ListBox2: TListBox;
ADODataSet1: TADODataSet;
Label3: TLabel;
Label4: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Panel1: TPanel;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
Label5: TLabel;
SQ: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListBox2Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var FieldNameParameter,sql:string;
begin
label3.Caption:=”;
label4.Caption:=”;
adodataset1.Close;
if edit1.Text=” then
begin
showmessage(‘Masukan Parameters pencarian’);
edit1.SetFocus;
abort;
end;
ListBox1.clear;
ListBox2.clear;
Animate1.Active:=true;
Animate1.Visible:=true;
if RadioButton4.Checked then
begin
QCari.close;
if RadioButton2.Checked then
begin
QCari.CommandText:=’select sys.schemas.name+”.”+sys.tables.name+” *** Fields ”+sys.columns.name+”***” as Name, ‘+
‘sys.tables.object_id,sys.schemas.name+”.”+sys.tables.name as Tabl,sys.columns.name as NameFild from sys.tables ‘+
‘inner join sys.schemas on sys.tables.schema_id=sys.schemas.schema_id ‘+
‘inner join sys.columns on sys.tables.object_id= sys.columns.object_id ‘+
‘where sys.columns.name=:name order by Name ‘;
Qcari.Parameters.ParamValues[‘name’]:=edit1.Text;
Qcari.open;
if QCari.recordcount>0 then
begin
QCari.first;
while not QCari.Eof do
begin
ListBox1.Items.Add(QCari.fieldbyname(‘name’).asstring);
ListBox2.Items.Add(‘select * from ‘+QCari.fieldbyname(‘tabl’).value);
QCari.Next;
end;
end;
end;
if RadioButton1.Checked then
begin
QCari.CommandText:=’select sys.schemas.name+”.”+sys.tables.name+” *** Fields ”+sys.columns.name+”***” as Name, ‘+
‘sys.tables.object_id,sys.schemas.name+”.”+sys.tables.name as Tabl,sys.columns.name as NameFild from sys.tables ‘+
‘inner join sys.schemas on sys.tables.schema_id=sys.schemas.schema_id ‘+
‘inner join sys.columns on sys.tables.object_id= sys.columns.object_id ‘+
‘where sys.columns.name like ‘+quotedstr(‘%’+edit1.text+’%’)+’ order by Name ‘;
Qcari.open;
if QCari.recordcount>0 then
begin
QCari.first;
while not QCari.Eof do
begin
ListBox1.Items.Add(QCari.fieldbyname(‘name’).asstring);
ListBox2.Items.Add(‘select * from ‘+QCari.fieldbyname(‘tabl’).value);
QCari.Next;
end;
end;
end;
end else
if RadioButton3.Checked then
begin
Qtable.close;
Qtable.open;
Qtable.first;
while not Qtable.Eof do
begin
QField.Close;
QField.Parameters.ParamValues[‘id’]:=Qtableobject_id.AsString;
QField.open;
QField.first;
while not QField.Eof do
begin
//===============================
if RadioButton2.Checked then
sql:=’select ‘+QFieldname.Value+’ from ‘+QtableName.AsString+’ where ‘+QFieldname.Value+’ = ‘+quotedstr(edit1.Text);
if RadioButton1.Checked then
sql:=’select ‘+QFieldname.Value+’ from ‘+QtableName.AsString+’ where ‘+QFieldname.Value+’ like ‘+quotedstr(‘%’+edit1.Text+’%’);
Qcari.Close;
Qcari.CommandText:=sql;
try
Qcari.open;
if Qcari.recordcount>0 then
begin
ListBox1.Items.Add(‘table : ‘+QtableName.AsString+’ *** Fields : ‘+QFieldname.Value+’***’);
if RadioButton2.Checked then
ListBox2.Items.Add(‘select * from ‘+QtableName.AsString+’ where ‘+QFieldname.Value+’=”’+edit1.Text+””);
if RadioButton1.Checked then
ListBox2.Items.Add(‘select * from ‘+QtableName.AsString+’ where ‘+QFieldname.Value+’ like ‘+quotedstr(‘%’+edit1.Text+’%’));
end;
except
end;
// end;
//===============================
QField.next;
end;
//=============================
Qtable.next;
end;
end;
Animate1.Active:=false;
Animate1.Visible:=false;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
var FICEini:string;
begin
Animate1.Active:=false;
Animate1.Visible:=false;
ADOConnection1.Connected := false;
ADOConnection1.ConnectionString := ‘FILE NAME=’+ExtractFilePath(Application.ExeName)+’pos.UDL’;
try
ADOConnection1.Connected := true;
except
showmessage(‘Can”t Connect DataBase, Contact your Administrator…’);
abort;
end;
end;
procedure TForm1.ListBox2Click(Sender: TObject);
var sql:string;
begin
sql:=ListBox2.Items.Strings[ListBox2.ItemIndex];
label3.Caption:=sql;
adodataset1.Close;
adodataset1.CommandText:=sql;
adodataset1.open;
label4.Caption:=’Jumlah Data yang ditemukan : ‘+inttostr(adodataset1.recordcount);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
ListBox2.ItemIndex:=ListBox1.ItemIndex;
ListBox2Click(Sender);
end;
end.
Filed under: Delphi Programming | Leave a comment »