Ado adalah salah satu object yang mampu menghubunkan database MS Acces dengan bahasa pemoggraman Delphi. Banyak hal yang berhubungan dengan database bias dikoneksikan dengan Ado tersebut
Recent Posts
Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi
(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita
Minggu, 15 November 2009
Membuat Ado Database Pada Delphi
Untuk memulai membuatkoneksi databasedengan ado pada delphi pertama-tama silahkan buat terlebih dahulu databasenya pada microsoft acces kemudian kasih nama database1.mdb.
Buat field no,nama,tgl, dan jenis pada table1 di database1.mdb tersebut
Source Code Delphi
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, Mask, DBCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
GroupBox1: TGroupBox;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
GroupBox2: TGroupBox;
DBGrid1: TDBGrid;
GroupBox3: TGroupBox;
Button4: TButton;
Label4: TLabel;
Button5: TButton;
DBEdit5: TDBEdit;
Label5: TLabel;
ADOQuery1: TADOQuery;
Edit1: TEdit;
DataSource2: TDataSource;
DBEdit4: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
DBEdit8: TDBEdit;
Label9: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
VAR lDBPathName: STRING;
begin
lDBPathName := ExtractFileDir(Application.ExeName) +'\database1.mdb';
ADOConnection1.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + lDBPathName + ';' +
'Persist Security Info=False;' +
'Jet OLEDB:Database Password=' + 'dengxiang';
ADOConnection1.Connected:=true;
adotable1.Active:=true;
end;
procedure TForm1.Button1Click(Sender: TObject); // tambah Data
var a: integer;
begin
adotable1.Append;
a:= adotable1.RecordCount;
a:=a+1;
dbedit5.Text:=inttostr(a);
end;
procedure TForm1.Button5Click(Sender: TObject); // simpan data
begin
Adotable1.Post;
end;
procedure TForm1.Button3Click(Sender: TObject); // delete data
var a: integer;
begin
a:= adotable1.RecordCount;
if a>1 then Adotable1.Delete;
end;
procedure TForm1.Button4Click(Sender: TObject); //cari data
var a: string;
begin
a:= edit1.Text;
adoquery1.Active:=false;
adoquery1.SQL.Clear;
with adoquery1 do
begin
Close;
SQL.Clear;
SQL.Add('select *'+'from table1 where (nama='''+a+''')');
ExecSQL;
Open;
end;
adoquery1.Active:=true;
end;
end.
0 komentar:
Posting Komentar