Author:zfive5(zhaozidong)
Email:[email protected]
用sql语句在access数据库中建立一张带自动增长字段的表(今天一位同事问了我这个问题),
我通过google收到所有access的保留字,看到AUTOINCREMENT才有的灵感,有关Access保留字
收藏在“我的收藏-寒江之雪"里,大家可以看看!
SQL语句:
CREATE TABLE AA
(
AA1 AUTOINCREMENT,
AA2 varchar(100)
)
VC代码:
//#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")
void CTestDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
::CoInitialize(NULL);
{
CString strConnection="";
CString strMsg="";
strConnection.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False;")\
,"c:\\db1.mdb");
_ConnectionPtr hAdoConnect;
HRESULT hr = hAdoConnect.CreateInstance( __uuidof(Connection) );
if ( FAILED(hr) )
{
::MessageBox(NULL,_T("您系统中的数据库驱动有问题。"), _T("提示"),
MB_OK | MB_ICONINFORMATION);
}
_RecordsetPtr rs;
CString strSql;
try
{
hAdoConnect->ConnectionTimeout = 18;
hAdoConnect->ConnectionString =_bstr_t(strConnection);
hAdoConnect->Open( _bstr_t(L""), _bstr_t(L""), _bstr_t(L""), -1 );
hAdoConnect->Execute(_bstr_t("CREATE TABLE AA(AA1 AUTOINCREMENT,AA2 varchar(100))"),NULL,adCmdText);
}
catch( _com_error& e)
{
_bstr_t bstrError = e.Description();
strMsg=(LPCTSTR)bstrError;
::MessageBox(NULL,strMsg, _T("提示"),
MB_OK | MB_ICONINFORMATION);
return;
}
}
CoUninitialize();
return;
}
本文地址:http://com.8s8s.com/it/it418.htm