|
-
July 4th, 2001, 08:32 AM
#1
Table existence
How to see (in C++) if a table exists in a database if we know its name?
Criniere Damien
---------------
-
July 9th, 2001, 01:48 AM
#2
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
-
July 9th, 2001, 04:39 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|