怎么在使用ADO建立数据库中表时判断该表是否存在
如何在使用ADO建立数据库中表时判断该表是否存在。
创建我知道是
g_pConn-> Execute( "CREATE TABLE account(ID INTEGER,username TEXT,old INTEGER,birthday DATETIME) ",&RecordsAffected,adCmdText);
但是如果这个表已经有了。就不要建立了。。怎么弄呢?
还有动态建立数据库的时候也是
m_pCatalog-> Create(_bstr_t(strcnn)); //Create MDBk可以建立数据库。
但是数据库建立的话就会转到catch去啦!虽然没什么影响
------解决方案--------------------
BOOL CDlgTest::CreateAccessTable()
{
_bstr_t strSQL;
CString strTemSQL;
CString str, str1, str2, str3;
CString strTabName,strName;
CStringArray stt;
CStringArray stTabName;
int i,n;
HRESULT hr(-1);
UpdateData(TRUE);
//OnSelchangeComboType();
n=m_List.GetItemCount();
stt.SetSize(n);
for (i=0;i <n;i++)
{
if(m_List.GetItemText(i,1)== "Text ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ") " + ", ";
}
else if (m_List.GetItemText(i,1)== "Autoincremnet ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if (m_List.GetItemText(i,1)== "Currency ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "DateTime ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Text ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ") " + ", ";
}
else if(m_List.GetItemText(i,1)== "Double ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Decimal ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ", " +
m_List.GetItemText(i,3) + ") " + ", ";
}
else if(m_List.GetItemText(i,1)== "Single ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Integer ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
/* else if (m_List.GetItemText(i,1)== "Yes ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}*/
stt[i] = strTemSQL;
}
str2 = m_List.GetItemText(0,0);
str3 = " ";
for(i=0;i <n;i++)
{
if(ListView_GetCheckState(m_List,i))
{
if(i> 0)
{
str1 = m_List.GetItemText(i,0);
str.Format( "%s,%s ",str2,str1);
str2 = str;
}
str.Format( "%s%s ",str3,stt[i]);
str3 = str;
}
}
// BOOL bOpenFileDialog= false;
// CString filepath;
// CString m_strResult;
// CString strName;
// LPCTSTR lpszDefExt = _T( " ");
// LPCTSTR lpszFileName= _T( "tabAccess ");
创建我知道是
g_pConn-> Execute( "CREATE TABLE account(ID INTEGER,username TEXT,old INTEGER,birthday DATETIME) ",&RecordsAffected,adCmdText);
但是如果这个表已经有了。就不要建立了。。怎么弄呢?
还有动态建立数据库的时候也是
m_pCatalog-> Create(_bstr_t(strcnn)); //Create MDBk可以建立数据库。
但是数据库建立的话就会转到catch去啦!虽然没什么影响
------解决方案--------------------
BOOL CDlgTest::CreateAccessTable()
{
_bstr_t strSQL;
CString strTemSQL;
CString str, str1, str2, str3;
CString strTabName,strName;
CStringArray stt;
CStringArray stTabName;
int i,n;
HRESULT hr(-1);
UpdateData(TRUE);
//OnSelchangeComboType();
n=m_List.GetItemCount();
stt.SetSize(n);
for (i=0;i <n;i++)
{
if(m_List.GetItemText(i,1)== "Text ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ") " + ", ";
}
else if (m_List.GetItemText(i,1)== "Autoincremnet ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if (m_List.GetItemText(i,1)== "Currency ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "DateTime ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Text ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ") " + ", ";
}
else if(m_List.GetItemText(i,1)== "Double ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Decimal ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + "( " +
m_List.GetItemText(i,2) + ", " +
m_List.GetItemText(i,3) + ") " + ", ";
}
else if(m_List.GetItemText(i,1)== "Single ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
else if(m_List.GetItemText(i,1)== "Integer ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}
/* else if (m_List.GetItemText(i,1)== "Yes ")
{
strTemSQL=m_List.GetItemText(i,0) + " " +
m_List.GetItemText(i,1) + ", ";
}*/
stt[i] = strTemSQL;
}
str2 = m_List.GetItemText(0,0);
str3 = " ";
for(i=0;i <n;i++)
{
if(ListView_GetCheckState(m_List,i))
{
if(i> 0)
{
str1 = m_List.GetItemText(i,0);
str.Format( "%s,%s ",str2,str1);
str2 = str;
}
str.Format( "%s%s ",str3,stt[i]);
str3 = str;
}
}
// BOOL bOpenFileDialog= false;
// CString filepath;
// CString m_strResult;
// CString strName;
// LPCTSTR lpszDefExt = _T( " ");
// LPCTSTR lpszFileName= _T( "tabAccess ");