zoukankan      html  css  js  c++  java
  • 判断数据库是否存在,表是否存在,否的话新建!

    void Caccess_test_1Dlg::existmdb()
    {
        if (!PathFileExists(_T(filename)))
        {
            AfxMessageBox(_T("数据库目前不存在!
    将重新为您创建数据库!"));
            //return;
            //创建数据库:新建一个Catalog对象,然后调用它的Create方法
            m_pCatalog = NULL;
            CString DBName = _T("Provider=Microsoft.JET.OLEDB.4.0;Data source=");
            CString str;
            str = _T(filename);
            DBName = DBName + str;
            try
            {
                m_pCatalog.CreateInstance(__uuidof(ADOX::Catalog));
                m_pCatalog->Create(_bstr_t((LPCTSTR)DBName));
            }
            catch (_com_error &e)
            {
                AfxMessageBox(e.ErrorMessage());
                return;
            }
            //连接数据库
            try
            {
                m_pConnection.CreateInstance(__uuidof(Connection));
                m_pConnection->Open(StrCmd, "", "", adModeUnknown);
            }
            catch (_com_error &e)
            {
                CString errormessage;
                errormessage.Format(_T("连接数据库失败!/r错误信息:%s"), e.ErrorMessage());
                AfxMessageBox(errormessage);
                return;
            }
            //createtable();
            existtable();
            return;
        }
        else
        {
            existtable();
        }
    }

    不能有那个return,不然没有数据库的话也不会重新创建一个新的~!

  • 相关阅读:
    MvvmLight:Command
    TreeView控件
    visual studio背景色
    公共语言运行时
    颜色列表
    自定义控件【旋转按钮,带圆角的边框】
    Loding Animation
    ComboBox前台xaml绑定数据
    Blend一些属性图解
    找到视觉树的方法
  • 原文地址:https://www.cnblogs.com/wxl845235800/p/7494676.html
Copyright © 2011-2022 走看看