CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Table existence

  1. #1
    Join Date
    Jul 2001
    Location
    France
    Posts
    17

    Table existence

    How to see (in C++) if a table exists in a database if we know its name?

    Criniere Damien
    ---------------

  2. #2
    Join Date
    Feb 2001
    Location
    Slovakia
    Posts
    18

    Re: Table existence

    For example execute this statement and check for result:

    select count(*) from sysobjects where id = object_id('table_name') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

    We have stored procedure for that which delivers back count and this we check in our C++.
    S


  3. #3
    Join Date
    Jul 2001
    Location
    France
    Posts
    17

    Re: Table existence

    thanks,
    i found another solution :


    bool Cbasededonnees::ExistenceTable(char * nom)
    {
    HRESULT hr = S_OK;
    HRESULT he = NULL;
    CString tmp = "Provider=Microsoft.JET.OLEDB.4.0;""Data source = "+Chemin+Fichier;
    _bstr_t strcnn(tmp);
    _CatalogPtr m_pCatalog = NULL;
    _TablePtr m_pTable = NULL;
    bool H=false;

    try
    {
    TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));
    //Open the catalog
    m_pCatalog->PutActiveConnection(strcnn);
    TESTHR(hr = m_pTable.CreateInstance(__uuidof(Table)));

    if (m_pCatalog->Tables->GetItem(nom)!= NULL)
    H=true;

    }
    catch(_com_error &e)
    {
    // Notify the user of errors if any.
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("\n\tSource : %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    }
    return H;
    }

    not really pretty but it works well





    Criniere Damien
    ---------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured