怎么在程序中创建access数据库?就是创建一个.mdb文件
然后怎么再在里面创建两个表?

解决方案 »

  1.   

    用ADOX
    ADO是不行滴
    如果你只考虑Access97的话DAO也可以
      

  2.   

    HRESULT hr = S_OK;
    hr = ::CoInitialize(NULL);
    if(SUCCEEDED(hr))
    {
    HRESULT hr = S_OK;
    // Define ADOX object pointers.
    // Initialize pointers on define.
    // These are in the ADOX::  namespace.
    ADOX::_CatalogPtr m_pCatalog = NULL;
    //Set ActiveConnection of Catalog to this string
    _bstr_t strcnn("Provider=Microsoft.JET.OLEDB.4.0;Data source=c:\\new.mdb");
    try
    {
    m_pCatalog.CreateInstance(__uuidof(ADOX::Catalog));
    m_pCatalog->Create(strcnn);
    }   
    catch(_com_error &e)
    {
    // Notify the user of errors if any.     
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    AfxMessageBox("Hello");
                    }
    }如果同时用 ADO 和 ADOX:
    #import "C:\program files\common files\system\ado\msado15.dll" rename("EOF","adoEOF")
    #import "C:\Program Files\Common Files\system\ado\msadox.dll"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admthcreatexvc.asp