Читайте также: |
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ExitButton: TButton;
AddButton: TButton;
DeleteButton: TButton;
SaveButton: TButton;
procedure FormShow(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure InsertButtonClick(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
procedure SaveButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AddButtonClick(Sender: TObject);
begin
ADOTable1.Edit;
ADOTable1.Append;
end;
procedure TForm1.DeleteButtonClick(Sender: TObject);
begin
ADOTable1.Edit;
ADOTable1.Delete;
end;
procedure TForm1.ExitButtonClick(Sender: TObject);
begin
close;
end;
procedure TForm1.FormShow(Sender: TObject);
var BaseName, ConString:string;
begin
BaseName:='test.mdb';
{файл должен находиться в корневом каталоге}
ConString:='Provider=Microsoft.Jet.OLEDB.4.0;Password="";User
ID=Admin;Data Source='+BaseName;
{создаем поля таблицы в DBGrid}
DBGrid1.Columns.Add;
DBGrid1.Columns[0].FieldName:='№';
DBGrid1.Columns[0].Width:=70;
DBGrid1.Columns.Add;
DBGrid1.Columns[1].FieldName:='Дата рождения';
DBGrid1.Columns[1].Width:=70;
DBGrid1.Columns.Add;
DBGrid1.Columns[2].FieldName:='Название предмета';
DBGrid1.Columns[2].Width:=80;
DBGrid1.Columns.Add;
DBGrid1.Columns[3].FieldName:='Класс;
DBGrid1.Columns[3].Width:=80;
AdoConnection1.ConnectionString:=ConString;
ADOTable1.TableName:='NewTable';
{указываем название таблицы в базе test.mdb}
AdoConnection1.Open;
AdoTable1.Active:=true;
end;
procedure TForm1.InsertButtonClick(Sender: TObject);
begin
ADOTable1.Edit;
ADOTable1.Insert;
end;
procedure TForm1.SaveButtonClick(Sender: TObject);
begin
ADOTable1.Edit;
ADOTable1.Post;
end;
end.
//Оболочка программы
object Form1: TForm1
Left = 0
Top = 0
Caption = 'ADO Example 1'
ClientHeight = 173
ClientWidth = 394
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 8
Top = 8
Width = 382
Height = 129
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object ExitButton: TButton
Left = 315
Top = 143
Width = 75
Height = 25
Caption = 'Exit'
TabOrder = 1
OnClick = ExitButtonClick
end
object AddButton: TButton
Left = 8
Top = 143
Width = 65
Height = 25
Caption = 'Add'
TabOrder = 2
OnClick = AddButtonClick
end
object DeleteButton: TButton
Left = 79
Top = 143
Width = 66
Height = 25
Caption = 'Delete'
TabOrder = 3
OnClick = DeleteButtonClick
end
object SaveButton: TButton
Left = 151
Top = 143
Width = 66
Height = 25
Caption = 'Save'
TabOrder = 4
OnClick = SaveButtonClick
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 16
Top = 56
end
object ADOConnection1: TADOConnection
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'Microsoft.Jet.OLEDB.4.0'
Left = 48
Top = 56
end
object ADOTable1: TADOTable
Connection = ADOConnection1
Left = 80
Top = 56
end
end
Дата добавления: 2015-08-03; просмотров: 186 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Переменные в среде программирования Delphi. | | | ПРЕДМЕТ КОНТРАКТА |