unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, DBCtrls, StdCtrls;
type
TForm1 = class(TForm)
DBLookupComboBox1: TDBLookupComboBox;
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
DataSource2: TDataSource;
Button1: TButton;
ADOTable1SIFRA: TStringField;
ADOTable1NAZIV: TStringField;
ADOTable2SIFRA: TStringField;
ADOTable2NAZIV: TStringField;
ADOQuery1: TADOQuery;
ADOTable2SJEDIS: TStringField;
ADOTable1SJEDIS: TStringField;
procedure Button1Click(Sender: TObject);
procedure ADOTable1AfterEdit(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var FirstValue:string;
begin
ADOTable1.Active:=true;
ADOTable2.Active:=true;
ADOTable1.Edit;
end;
procedure TForm1.ADOTable1AfterEdit(DataSet: TDataSet);
var FirstValue:string;
begin
ADOQuery1.Active:=false;
ADOQuery1.SQL.Text:=
'select top 1 sifra from fs01 ';
ADOQuery1.Active:=True;
FirstValue:= ADOQuery1.fieldbyname('sifra').AsString;
DBLookupComboBox1.KeyValue:=FirstValue;
end;
end.
////////////////////////////////////////////////////////////////
dfm:
object Form1: TForm1
Left = 633
Top = 104
Width = 493
Height = 350
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBLookupComboBox1: TDBLookupComboBox
Left = 64
Top = 120
Width = 281
Height = 21
DataField = 'SJEDIS'
DataSource = DataSource1
KeyField = 'SIFRA'
ListField = 'NAZIV'
ListFieldIndex = 15
ListSource = DataSource2
TabOrder = 0
end
object Button1: TButton
Left = 128
Top = 232
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 56
Top = 16
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initi' +
'al Catalog=DB2007;Data Source=.'
Provider = 'SQLOLEDB.1'
Left = 104
Top = 16
end
object ADOTable1: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
AfterEdit = ADOTable1AfterEdit
TableName = 'FS01'
Left = 160
Top = 16
object ADOTable1SIFRA: TStringField
FieldName = 'SIFRA'
Size = 15
end
object ADOTable1NAZIV: TStringField
FieldName = 'NAZIV'
Size = 60
end
object ADOTable1SJEDIS: TStringField
FieldName = 'SJEDIS'
Size = 60
end
end
object ADOTable2: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'FS01'
Left = 288
Top = 32
object ADOTable2SIFRA: TStringField
FieldName = 'SIFRA'
Size = 15
end
object ADOTable2NAZIV: TStringField
FieldName = 'NAZIV'
Size = 60
end
object ADOTable2SJEDIS: TStringField
FieldName = 'SJEDIS'
Size = 60
end
end
object DataSource2: TDataSource
DataSet = ADOTable2
Left = 304
Top = 64
end
object ADOQuery1: TADOQuery
Connection = ADOConnection1
Parameters = <>
Left = 16
Top = 16
end
end
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168:





by: Geert_GruwezPosted on 2009-07-12 at 22:39:30ID: 24837390
use the AfterInsert event of the dataset to set any intial fields in the inserted record
if you want the first record, then you may need to execute a separate query to know which is first
this will also depend on sorting
Select allOpen in new window