这样会错,在建新有时会报错,这里把建新表代码移到判断外面,重新运行,就没问题,怎么一次完成库和表的创建?
s.Format(_T("SELECT * FROM sysdatabases WHERE name='ShowPrintDb'"));
pRs->Open(_bstr_t(s),m_pConn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
if (pRs->GetRecordCount()<1) {//not exist, create one
s=_T("CREATE DATABASE ShowPrintDb");
m_pConn->Execute(_bstr_t(s),NULL,adCmdText);
s=_T("CREATE TABLE ShowPrintDb..picdata")
_T("(id varchar(50) PRIMARY KEY CLUSTERED,")
_T("keywords varchar(200),")
_T("pic0 image,")
_T("pic1 image,")
_T("pic2 image,")
_T("pic3 image,")
_T("pic4 image,")
_T("pic5 image,")
_T("pic6 image,")
_T("pic7 image,")
_T("pic8 image,")
_T("pic9 image,")
_T("pic10 image)");
m_pConn->Execute(_bstr_t(s),NULL,adCmdText);
}