Question

I am using very similar syntax to delete Query's but when I try to check if a table exists and delete it the table is not actually deleted. Did I miss a step or use incorrect syntax?

string path = "C:\\Database\\EmployeeInfo\\EmpInfo.mdb";
bool found = false;
DAO.DBEngine db = new DAO.DBEngine();
dd = db.OpenDatabase(path);
try
{
  string[] tableNames = new string[3]
  {
    supName + "_Profile1",
    supName + "_Profile2",
    supName + "_Profile3",
  };
  for (int q = tableNames.GetLowerBound(0); q <= tableNames.GetUpperBound(0); q++)
  {
    foreach (DAO.TableDef tabledef in dd.TableDefs)
    {
      string newName = Convert.ToString(q);
      if (tabledef.Name == newName)
      {  
        found = true;
      }
      if (found)
      {
        dd.TableDefs.Delete(newName);
      }
    }
  }
}

EDIT --- Simple Syntax mistake....the code should have been:

string newName = tableNames[q];
Was it helpful?

Solution

It looks as though you meant to build up the new name? Currently you have

string newName = Convert.ToString(q);

so newName is only ever a number. Unlikely to match your table names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top