does anybody know how can I get the primary(ies) key(s) field(s) of a
table, using TAdoTable ?
Thanks for your attention.
Here is an example
ADOConnection1.OpenSchema(siPrimaryKeys
,VarArrayOf([Null,Null,'YourTblName']),EmptyParam,ADODataSet1);
--
Brian Bushay (TeamB)
Bbu...@NMPLS.com
Brian Bushay TeamB <BBu...@Nmpls.com> escreveu nas notícias de
mensagem:j7go0u8lpris6d84d...@4ax.com...
> Even if a try to use the interface class "_Table" ? Is there any way
to get
> this class from TADOTable ? Like, I don´t know, "GetInterface"
procedure ?
In fact, TADOTable is based on a ADO Recordset object, not on a ADOX
Table object. The "Table" in its name only indicates it can be a
substitute for a TTable object for programs written for the BDE.
TADOTable, TADOQuery and TADODataSet are all descendants from
TCustomADODataSet, and the interface they provide is _Recordset.
If you import the ADOX type library, you can access the Keys collection
of the Table object and read the column names of the primary key. If you
want an example of using ADOX, have a look at this code by DRS:
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=15292
It shows (notably) how to add a multi-column primary key to a table.
Adding a key will only work with Jet 4.0, but reading it should work
with other providers.
But if you can, it is probably simpler to use OpenSchema as Brian
suggested.
Thérèse
Thanks a lot...
Using the "connection" property of the TADOTable class, it is possible to
get the "_Connection" ADOX object.
With this object we can create a "_Catalog" object using this connection. In
this "_Catalog" object, there is a property named "Tables" that it's
possible to return all tables of the catalog in use, and selecting the
wanted table, its returns an "_Table" object from this table, where I can
get its primary keys.
The source code:
with ADOTable1 do begin
oCatalogo := CoCatalog.Create;
oCatalogo.Set_ActiveConnection(Connection.ConnectionObject);
Result := '';
with oCatalogo.Tables.Item[TableName].Indexes[0] do begin
for n := 0 to Columns.Count-1 do Result := Result + Columns[n].Name +
';';
end;
Result := Copy(Result, 1, Length(Result)-1);
oCatalogo.Set_ActiveConnection(Unassigned);
oCatalogo := nil;
end;
> Using the "connection" property of the TADOTable class, it is possible
to
> get the "_Connection" ADOX object.
> With this object we can create a "_Catalog" object using this
connection.
Yes, you can use any ADO object connected to your database, or even the
underlying _Connection object of the TADOConnection itself if you have
one for several objects.
You can also establish the connection on basis of the ConnectionString,
using the _Set_ActiveConnection method.
> with oCatalogo.Tables.Item[TableName].Indexes[0] do begin
> for n := 0 to Columns.Count-1 do Result := Result +
Columns[n].Name +
> ';';
Unless you are sure, I would advise checking if the first index is a
primary key (PrimaryKey property should be true).
Alternately, you can use the Keys collection instead of the Indexes
collection, and check that the Type property of the Key is adKeyPrimary.
Thérčse