Re: Make column indexed
- From: MikeR <nf4lNoSpam@xxxxxxxxx>
- Date: Sat, 19 May 2007 11:46:49 -0400
Brian Hollister wrote:
try here to, you'll probably need to find the right version for yourself:Thanks Brian -
http://msdn2.microsoft.com/en-us/office/aa905400.aspx
I didn't know about the VBA help file. Took a while to find it. I don't speak enough VBA to be able to get enough from it.
M$ makes me crazy with their code examples that do not match the prototypes.
Between the MSDN site you referenced (and some more Googling), this works:
procedure TForm1.Button1Click(Sender: TObject);
var
sql: string;
cat: ADOX_TLB._Catalog;
col : ADOX_TLB._Column;
table : ADOX_TLB._Table;
ndx: ADOX_TLB._Index;
Connection: ADODB_TLB._Connection;
fName: olevariant;
begin
Connection := adodb_tlb.CoConnection.Create;
Connection.ConnectionString := DataSource;
//Get exclusive access to modify the database's structure. Default adModeUnknown.
Connection.Mode := adModeShareExclusive;
Connection.Open('', '', '', 0); //unassigned
Cat := CoCatalog.Create;
// Link the Catalog object to the open connection
Cat._Set_ActiveConnection(Connection);
fname := 'RecID';
table := Cat.Tables['Log'];
label1.Refresh;
col := CoColumn.Create ;
//col.Properties
with col do
begin
ParentCatalog := cat;
Name := fName;
Type_ := adInteger;
Properties['AutoIncrement'].Value := true;
table.Columns.Append(col, Unassigned, Unassigned);
end;
ndx := Adox_tlb.CoIndex.Create; // This one was a bear!
ndx.Name := 'RecIDx';
ndx.IndexNulls := adIndexNullsDisallow;
//ndx.Unique := true; //does nothing to prevent duplicates
table.Keys.Append('RID', adKeyUnique, 'RecID','Log','RecID'); //Prevent duplicates
ndx.Columns.Append('RecIDx',adInteger,0);
table.Indexes.Append('RecIDx', 'RecID');
end;
.
- References:
- Make column indexed
- From: MikeR
- Re: Make column indexed
- From: Brian Hollister
- Re: Make column indexed
- From: Brian Hollister
- Make column indexed
- Prev by Date: Re: My access database file just keeps getting bigger
- Next by Date: 'Registering' ADO Dlls
- Previous by thread: Re: Make column indexed
- Next by thread: Nested datasets, Aggregates and calculated fields
- Index(es):