Yaz  Font K   lt Yaz  Font B y lt

ADOQuery da InsertRecord Metoduyla Kayýt Giriþi

 

Merhaba arkadaþlar bu makalemizde ADOQuery nesnesinde Insert Record özelliðini kullanarak Access veritabanýmýzdaki tablomuza kayýt gireceðiz. Formumuza 1 adet DBGrid ve 1 Button ekliyoruz. Ayrica Palette kismindan 1 adet ADOQuery ve DataSource ekliyoruz.

FormCreate kýsmýnda DBGrid nesnemize sutunlari ekliyoruz.

Daha onceki makalede veritabanina nasil baglanilir detayli anlatmistim. Onceki makaleye buradan ulasabilirsiniz. 

 

 

 

Resim1

Þekil 1



 

 

 

Resim1

Þekil 2

 

 

unit add_columns_Unit1;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.StdCtrls, Vcl.Grids,

Vcl.DBGrids, Data.Win.ADODB;

type

TForm1 = class(TForm)

DBGrid1: TDBGrid;

Button1: TButton;

DataSource1: TDataSource;

ADOQuery1: TADOQuery;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;

DataCol: Integer; Column: TColumn; State: TGridDrawState);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

ADOQuery1.InsertRecord([1,'Tom''Hanks''Actor']);

end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;

DataCol: Integer; Column: TColumn; State: TGridDrawState);

begin

if DataSource1.DataSet.RecNo>=then

begin

if Column.Title.Caption = 'Id' then

DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo));

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

DBGrid1.Columns.Add;

DBGrid1.Columns[0].FieldName:='Id';

DBGrid1.Columns.Add;

DBGrid1.Columns[1].FieldName:='FirstName';

DBGrid1.Columns.Add;

DBGrid1.Columns[2].FieldName:='LastName';

DBGrid1.Columns.Add;

DBGrid1.Columns[3].FieldName:='Explanation';

end;

end.

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüþmek üzere. Bahadýr ÞAHÝN