Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I copy all indexes of one MS-Access table to another via DAO?

Posted on 2008-10-27
2
Medium Priority
?
291 Views
Last Modified: 2012-05-05
My C# code (which references Microsoft DAO 3.6 Object Library) contains objects called fromTable and toTable, both defined as DAO.TableDef objects.
I am trying to copy all the indexes of fromTable into toTable but when I try to compile the attached code snippet I get the following error message on the second foreach statement:

foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'

I also get the following error message that carries the same meaning on the next line:

'object' does not contain a definition for 'Append'

How can I copy a DAO.Index object if its Fields member is defined as a plain object?
DAO.Index toIndex;
foreach (DAO.Index fromIndex in fromTable.Indexes)
{
    toIndex = toTable.CreateIndex(fromIndex.Name);
    foreach (DAO.Field field in fromIndex.Fields)
        toIndex.Fields.Append(toIndex.CreateField(field.Name, field.Type, field.Size));
    toTable.Indexes.Append(toIndex);
}

Open in new window

0
Comment
Question by:netformx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Priest04 earned 1000 total points
ID: 22820289
Try casting Fields to IndexFields


foreach (DAO.Index fromIndex in fromTable.Indexes)
{
    toIndex = toTable.CreateIndex(fromIndex.Name);
    foreach (DAO.Field field in ((DAO.IndexFields) fromIndex.Fields))
        ((DAO.IndexFields)toIndex.Fields).Append(toIndex.CreateField(field.Name, field.Type, field.Size));
    toTable.Indexes.Append(toIndex);
}

Open in new window

0
 

Author Closing Comment

by:netformx
ID: 31510356
Genius!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question