Damien Criniere
July 4th, 2001, 08:32 AM
How to see (in C++) if a table exists in a database if we know its name?
Criniere Damien
---------------
Criniere Damien
---------------
|
Click to See Complete Forum and Search --> : Table existence Damien Criniere July 4th, 2001, 08:32 AM How to see (in C++) if a table exists in a database if we know its name? Criniere Damien --------------- Slavo Hodul July 9th, 2001, 01:48 AM 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 Damien Criniere July 9th, 2001, 04:39 AM 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 --------------- codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |