I am trying to create an ADO Connection with a Table at Run Time and activate a DBGrid with the data. I have researched the web and created the following code that I hope will create the ADOConnection and the Table.
procedure TForm1.Button_CreateClick(Sender: TObject);
var
DskDrive: string;
MyPath: string;
MYDb: TADOConnection;
MyTbl1: TADOTable;
MyTbl2: TADOTable;
MyDBS: TDataSource;
begin
DskDrive := ExtractFileDrive(ParamStr(0));
MyPath := DskDrive + '//My Files/Columbia/Data/Columbia-2012.mdb';
MyDb := TADOConnection.Create(Self);
MyDb.Close;
MyDb.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + MyPath + ';' +
'Persist Security Info=True;';
MyDb.LoginPrompt :=False;
MyDb.Connected := True;
MyDb.Open;
MyTbl1 := TADOTable.Create(Self);
MyTbl1.Active := false;
MyTbl1.Connection := MyDb;
MyTbl1.TableName := 'Table1';
MyTbl1.Open;
MyDBS := TDataSource.Create(Self);
MyDBS.DataSet := MyTbl1;
end;
Please refiew this code and advise me if it is correct or wher it needs to be changed.
Once this works I need to configure the DBGrid to display two columns, LastName and FirstName. How can that be done?
On the Form I have a ADOConnection1, an ADOTable1,an ADODataSource1 and a DBGrid1 with two undefined columns.
procedure TForm1.Button_CreateClick(Sender: TObject);
var
DskDrive: string;
MyPath: string;
MYDb: TADOConnection;
MyTbl1: TADOTable;
MyTbl2: TADOTable;
MyDBS: TDataSource;
begin
DskDrive := ExtractFileDrive(ParamStr(0));
MyPath := DskDrive + '//My Files/Columbia/Data/Columbia-2012.mdb';
MyDb := TADOConnection.Create(Self);
MyDb.Close;
MyDb.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + MyPath + ';' +
'Persist Security Info=True;';
MyDb.LoginPrompt :=False;
MyDb.Connected := True;
MyDb.Open;
MyTbl1 := TADOTable.Create(Self);
MyTbl1.Active := false;
MyTbl1.Connection := MyDb;
MyTbl1.TableName := 'Table1';
MyTbl1.Open;
MyDBS := TDataSource.Create(Self);
MyDBS.DataSet := MyTbl1;
end;
Please refiew this code and advise me if it is correct or wher it needs to be changed.
Once this works I need to configure the DBGrid to display two columns, LastName and FirstName. How can that be done?
On the Form I have a ADOConnection1, an ADOTable1,an ADODataSource1 and a DBGrid1 with two undefined columns.