ADOX Index Creation Problem

L

localhost

I am using ADOX to create databases and tables. I can create tables
and columns fine. I am having a problem with making indexes. I am
using MDAC 2.8 with ADOX and ADODB type libraries added as references
to my Visual Studio 2003 C# console app project.

ADOX.IndexClass newIndex = new ADOX.IndexClass();
newIndex.Name = "testIndex";
newIndex.Columns.Append(
(object)"testCol" ,
ADOX.DataTypeEnum.adVarWChar ,
16 );
testTable.Indexes.Append( (object)newIndex , null );

This works fine, but I cannot determine how to set the Sort Order for
the index, I can only get the acending default.

Thanks.
 
C

Cor

Hi Localhost,

Why not use ADOX only to create a mdb file.

The rest you can do with adonet with the sql "create" and the
command.executenonquery.

Very easy and consistent

Just my thought

Cor
 
K

Kevin Yu [MSFT]

Hi localhost,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to changed the sort order of
an index column with ADOX. If there is any misunderstanding, please feel
free to let me know.

In ADOX, we can use the SortOrder property of a column to specify the sort
order for a column in an index. Here I have made some changes to your code.

ADOX.Index newIndex = new ADOX.IndexClass(); //please declare newIndex as
ADOX.Index. It's better to manipulate on the interface instead of object.
newIndex.Name = "testIndex";
newIndex.Columns.Append("testCol", ADOX.DataTypeEnum.adVarWChar, 16);
newIndex.Columns["testCol"].SortOrder =
ADOX.SortOrderEnum.adSortDescending;
testTable.Indexes.Append(newIndex , null );

For more information about the SortOrder property and Columns.Append
method, please check the following links for reference:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/
adprosortorder.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/
admthappendcolumns.asp

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top