문제

I have the following syntax to use C# to delete an access query...but how do I 1st check if the query exists?

DAO.Database dd;
DAO.DBEngine db = new DAO.DBEngine();
dd = db.OpenDatabase(path);
dd.QueryDefs.Delete(queryName);

I also tried this -- but received a compile error of 'Can not assign to 'Equals' because it is a 'method group'

var qd = new DAO.QueryDef();
if (qd.Name.Equals = "Hello")
{
  dd.QueryDefs.Delete(queryName);
}
도움이 되었습니까?

해결책 2

You can loop over the QueryDefs collection and check if you find it...

DAO.Database dd;
DAO.DBEngine db = new DAO.DBEngine();
dd = db.OpenDatabase(path);
bool found= false;
foreach(DAO.QueryDef qd in dd.QueryDefs)
{
   if (qd.Name == "Hello")
   {
        found = true;
   }
}
if (found)
{
   dd.QueryDefs.Delete(queryName);
}

다른 팁

Try this SQL query:

SELECT * FROM MSysObjects
WHERE Name="MyQuery" AND Type=5

If you get results, the query exists. Type=5 is for queries (at least in the database I looked at).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top