如何使用C#interop传递dbFailOnError参数?

时间:2013-02-28 17:46:37

标签: c# ms-access office-interop

我正在使用DAO在Access数据库上执行SQL语句。如果我使用VBA,如果更新查询失败,我可以使用dbFailOnError抛出错误,如下所示:

function updateTable(db as DAO.Database) as boolean

 on error goto errHandler
 db.execute "update testTable set name='xyz' where name='abc'",dbFailOnError
 updateTable=true
 exit function

 errhandler:
  updateTable=false
  on error goto 0

end function

如何使用.NET Interop传递dbFailOnError?似乎相当于:

using Dao = Microsoft.Office.Interop.Access.Dao;
namespace DatabaseFunctions
{
    public class Updater
    {
        public bool updateTable(Dao.Database db)
        {
            try
            {
             db.Execute("update testTable set name='xyz' where name='abc'",
                         dbFailOnError);
             return true;
            }
            catch
            {
             return false;
            }
        }
    }
}

但我找到dbFailOnError的名称空间是什么?它不在Dao

1 个答案:

答案 0 :(得分:2)

dbFailOnErrorDAO枚举的成员,RecordsetOptionEnum ...所以请尝试DAO.RecordsetOptionEnum.dbFailOnError