unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBTables,
DB, StdCtrls, Grids, DBGrids,ComCtrls, ExtCtrls, DBCtrls,
ZConnect, ZMySqlCon, ZQuery, ZMySqlQuery, ZTransact, ZMySqlTr;
type
TForm1 =
class(TForm)
Btabanlegen: TButton;
Ehost: TEdit;
Euser: TEdit;
Epw: TEdit;
edb: TEdit;
Host: TLabel;
User: TLabel;
Label3: TLabel;
Database: TLabel;
dsmain: TDataSource;
beintragen: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Banzeigen: TButton;
StringGrid1: TStringGrid;
trmain: TZMySqlTransact;
qrmain: TZMySqlQuery;
dbmain: TZMySqlDatabase;
procedure BtabanlegenClick(Sender: TObject);
procedure beintragenClick(Sender: TObject);
procedure BanzeigenClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BtabanlegenClick(Sender: TObject);
begin
dbMain.Host:=ehost.Text;
//Server
dbMain.Login:=euser.Text;
//Benutzername
dbMain.Password:=epw.Text;
//Passwort
dbMain.Database:=edb.Text;
//Name der Datenbank
dbMain.Connected:=True;
//Verbindung herstellen
try
qrMain.SQL.Text:='
CREATE TABLE `adressbuch` ('+
'
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,'+
'
`vorname` TEXT NOT NULL,'+
'
`name` TEXT NOT NULL,'+
'
`adresse` TEXT NOT NULL,'+
'
`wohnort` TEXT NOT NULL,'+
'
`plz` INT NOT NULL'+
'
);';
qrMain.ExecSql;
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.beintragenClick(Sender: TObject);
begin
dbMain.Host:=ehost.Text;
//Server
dbMain.Login:=euser.Text;
//Benutzername
dbMain.Password:=epw.Text;
//Passwort
dbMain.Database:=edb.Text;
//Name der Datenbank
dbMain.Connected:=True;
//Verbindung herstellen
try
qrMain.SQL.Text:='
INSERT INTO `adressbuch` '+
'
(`id`, `vorname`, `name`, `adresse`, `wohnort`, `plz`)'+
'
VALUES '+
'
(''
''
, ''
'+edit1.Text+'
''
, ''
'+edit2.Text+
'
''
, ''
'+edit3.Text+'
''
, ''
'+edit4.Text+
'
''
, ''
'+edit5.Text+'
''
);';
qrMain.ExecSql;
//SQL-Statement ausführen
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.BanzeigenClick(Sender: TObject);
var
i, j,k :integer;
begin
dbMain.Host:=ehost.Text;
//Server
dbMain.Login:=euser.Text;
//Benutzername
dbMain.Password:=epw.Text;
//Passwort
dbMain.Database:=edb.Text;
//Name der Datenbank
dbMain.Connected:=True;
//Verbindung herstellen
qrmain.SQL.Text:='
Select * from `adressbuch` order by name;';
qrmain.Open;
stringgrid1.rowcount:=0;
stringgrid1.Cells[0,0] := '
id';
stringgrid1.Cells[1,0] := '
Vorname:';
stringgrid1.Cells[2,0] := '
Name:';
stringgrid1.Cells[3,0] := '
Adresse:';
stringgrid1.Cells[4,0] := '
Wohnort:';
stringgrid1.Cells[5,0] := '
PLZ';
k := qrmain.RecordCount;
//showmessage(inttostr(k));
for i := 1
to k
do
begin
stringgrid1.RowCount := stringgrid1.RowCount + 1;
stringgrid1.Cells[1,i] := qrMain.FieldByName('
vorname').AsString;
stringgrid1.Cells[2,i] := qrMain.FieldByName('
name').AsString;
stringgrid1.Cells[0,i] := qrMain.FieldByName('
id').AsString;
stringgrid1.Cells[3,i] := qrMain.FieldByName('
adresse').AsString;
stringgrid1.Cells[4,i] := qrMain.FieldByName('
wohnort').AsString;
stringgrid1.Cells[5,i] := qrMain.FieldByName('
plz').AsString;
qrmain.Next;
end;
qrmain.Close;
end;
end.