您如何后折线数据库值值?

发布于 2025-02-01 10:15:08 字数 1744 浏览 3 评论 0原文

databasetypeenum值列出了在这里

您如何 late Bind 值?

目前,我正在传递文字整数:

  • 64 dbversion40
  • 128 for dbversion120

这是上下文中的当前代码:

public bool CompactAccessDatabase(string strSourceDB, string strTargetDB, string strPassword, int iMode)
{
    try
    {
        // Get the DBEngine property
        dynamic dbEngine = Activator.CreateInstance(Type.GetTypeFromProgID("DAO.DBEngine.120"));

        // Build the DB connection string
        string strDecryptedPassword = "";
        string strDBConnectionString = "";
        if(!string.IsNullOrEmpty(strPassword))
        {
            if (!DecryptDatabasePassword(strPassword, ref strDecryptedPassword))
            {
                SimpleLog.Log("DecryptDatabasePassword returned false");
            }
            strDBConnectionString = ";pwd=" + strDecryptedPassword;
        }

        int iOptions = 0;   // To Compact
        if (iMode == 1)     // To MDB
            iOptions = 64;  // DatabaseTypeEnum.dbVersion40 
        else if(iMode == 2) // To ACCDB
            iOptions = 128; // DatabaseTypeEnum.dbVersion120

        // Perform the compact
        dbEngine.CompactDatabase(strSourceDB, strTargetDB, "", iOptions, strDBConnectionString);
    }
    catch (Exception ex)
    {
        SimpleLog.Log(ex);
        return false;
    }

    return true;
}

可以迟到固定枚举ID吗?还是最好使用硬编码值?

The DatabaseTypeEnum values are listed here.

How do you late bind the values?

At the moment I am passing literal integers:

  • 64 for dbVersion40
  • 128 for dbVersion120

This is the current code in context:

public bool CompactAccessDatabase(string strSourceDB, string strTargetDB, string strPassword, int iMode)
{
    try
    {
        // Get the DBEngine property
        dynamic dbEngine = Activator.CreateInstance(Type.GetTypeFromProgID("DAO.DBEngine.120"));

        // Build the DB connection string
        string strDecryptedPassword = "";
        string strDBConnectionString = "";
        if(!string.IsNullOrEmpty(strPassword))
        {
            if (!DecryptDatabasePassword(strPassword, ref strDecryptedPassword))
            {
                SimpleLog.Log("DecryptDatabasePassword returned false");
            }
            strDBConnectionString = ";pwd=" + strDecryptedPassword;
        }

        int iOptions = 0;   // To Compact
        if (iMode == 1)     // To MDB
            iOptions = 64;  // DatabaseTypeEnum.dbVersion40 
        else if(iMode == 2) // To ACCDB
            iOptions = 128; // DatabaseTypeEnum.dbVersion120

        // Perform the compact
        dbEngine.CompactDatabase(strSourceDB, strTargetDB, "", iOptions, strDBConnectionString);
    }
    catch (Exception ex)
    {
        SimpleLog.Log(ex);
        return false;
    }

    return true;
}

Is it possible to late bind the enum ids instead? Or is it best to use hard coded values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我一直都在从未离去 2025-02-08 10:15:08

只需将其使用到int:

if (iMode == 1)     // To MDB
            iOptions = (int)DatabaseTypeEnum.dbVersion40 ;
        else if(iMode == 2) // To ACCDB
            iOptions = (int)DatabaseTypeEnum.dbVersion120;

https://wwww.tutorialsteacher .com/articles/convert-int-to-enum-in-csharp

Just use cast it to int:

if (iMode == 1)     // To MDB
            iOptions = (int)DatabaseTypeEnum.dbVersion40 ;
        else if(iMode == 2) // To ACCDB
            iOptions = (int)DatabaseTypeEnum.dbVersion120;

https://www.tutorialsteacher.com/articles/convert-int-to-enum-in-csharp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文