Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Table Info of a mdb database!!!

Hi,

I have used the following code to get table info from my database.
My database contains only one table.
I don't know why the index value must be set to 4 in order to get the name of the table.

Can anyone tell me what is the use of the value index?
If my database contain only one table, why I can't get the name of the table by setting the value of index equal to 0.

--------------------------------------------------------------------------
CDaoTableDefInfo TableInfo;
int index=0;
BOOL lp= TRUE;
while (lp)
{
m_pDBList->GetTableDefInfo(index,TableInfo,AFX_DAO_ALL_INFO);
if (!(TableInfo.m_lAttributes & dbSystemObject)&& !(TableInfo.m_lAttributes & dbHiddenObject))
{
break;
}
  index++;
}

--------------------------------------------------------------------------


Thanks!!!
0
ee_lcpaa
Asked:
ee_lcpaa
  • 2
  • 2
1 Solution
 
inprasCommented:
Hi

Index is just a look up number of the perticular tabledef collection in the database it doesn't have to do any thing with the number of tables present in the database.
0
 
SamHobbsCommented:
inpras is probably correct.

There are also hidden and system tables, correct? I am only guessing, but perhaps they use index values that are less than 4.
0
 
SamHobbsCommented:
I forgot to mention something. Did you try doing something like setting a breakpoint on the if statement after the GetTableDefInfo call to see what the results were for indexes 0 to 4?
0
 
V_BapatCommented:
I am not sure about this but...
It may be so that 5 tables were created and the first 4 were deleted.

Can you try creating this table and then get the table info?
0
 
V_BapatCommented:
These are the first 4 system tables:

Index   Table name
 0        MSysACEs
 1        MySysObjects
 2        MySysQueries
 3        MySysRelationships

That is why your table index is 4.

If you want to get only the user tables, you can try something like this:

CDaoTableDefInfo tdiTableInfo;
long lTableCount = m_pDBList->GetTableDefCount();

for(int i = 0; i < lTableCount; i++)
{
   m_pDBList->GetTableDefInfo(i, tdiTableInfo, AFX_DAO_ALL_INFO);

   if(tdiTableInfo.m_lAttributes & dbSystemObject | tdiTableInfo.m_lAttributes & dbHiddenObject)
      continue;

// tdiTableInfo.m_strName contains the table name.
// Display it.
   AfxMessageBox(tdiTableInfo.m_strName);
}

Vicky
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now