问题:MFC 动态创建access数据库,并建立表,出现错误,请高手指教,总是说:sql语句错误 10
BOOLCSysApp::ConnectionDb()//连接数据库{CTimetm=CTime::GetCurrentTime();CStringDBFile=tm.F...
BOOL CSysApp::ConnectionDb()
//连接数据库
{
CTime tm=CTime::GetCurrentTime();
CString DBFile=tm.Format("%Y%m%d%H%M%S.mdb");
if(!CreateDbFile(DBFile))
return FALSE;
// if(!OpenDbFile(DBFile))
// return FALSE;
///////////////////////////////////////////////
///SQL 创建表info 语句
try
{
CString //sql="create table info(`ID` int)";
sql="CREATE TABLE info (`ID` int not null auto_increment primary key,`Channel` int not null,`Date` Text(50) not null,`Time` Text(50) not null,`CurrDyz` FLOAT not null,`DyMax` Float not null,`DyMin` Float not null,`IsWarn` int not null)";
m_pobjDaoQd->Create(NULL,sql);
// m_pobjDaoRs->Close();
}
catch(CDaoException *e)
{
char ch[255];
e->GetErrorMessage(ch,255);
e->Delete();
AfxMessageBox(ch);
return FALSE;
}
m_pConnection.CreateInstance(_uuidof(Connection));
CString strConn;
strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Mode=ReadWrite;Persist Security Info=False",DBFile);
try
{
m_pConnection->Open((_bstr_t)strConn,"","",adModeUnknown);
}
catch(_com_error e)
{
CString str;
str.Format("警告:打开连接发生异常。错误信息:%s",e.ErrorMessage());
AfxMessageBox(str);
return FALSE;
}
return TRUE;
}
int CSysApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
if(m_pConnection->State)
{
m_pConnection->Close();
m_pConnection=NULL;
}
return CWinApp::ExitInstance();
}
BOOL CSysApp::CreateDbFile(CString strFileName)
//创建数据库文件
{
try
{
m_pobjDaoDb->Create(strFileName);
}
catch(CDaoException *e)
{
char ch[255];
e->GetErrorMessage(ch,255);
e->Delete();
AfxMessageBox(ch);
return FALSE;
}
return TRUE;
} 展开
//连接数据库
{
CTime tm=CTime::GetCurrentTime();
CString DBFile=tm.Format("%Y%m%d%H%M%S.mdb");
if(!CreateDbFile(DBFile))
return FALSE;
// if(!OpenDbFile(DBFile))
// return FALSE;
///////////////////////////////////////////////
///SQL 创建表info 语句
try
{
CString //sql="create table info(`ID` int)";
sql="CREATE TABLE info (`ID` int not null auto_increment primary key,`Channel` int not null,`Date` Text(50) not null,`Time` Text(50) not null,`CurrDyz` FLOAT not null,`DyMax` Float not null,`DyMin` Float not null,`IsWarn` int not null)";
m_pobjDaoQd->Create(NULL,sql);
// m_pobjDaoRs->Close();
}
catch(CDaoException *e)
{
char ch[255];
e->GetErrorMessage(ch,255);
e->Delete();
AfxMessageBox(ch);
return FALSE;
}
m_pConnection.CreateInstance(_uuidof(Connection));
CString strConn;
strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Mode=ReadWrite;Persist Security Info=False",DBFile);
try
{
m_pConnection->Open((_bstr_t)strConn,"","",adModeUnknown);
}
catch(_com_error e)
{
CString str;
str.Format("警告:打开连接发生异常。错误信息:%s",e.ErrorMessage());
AfxMessageBox(str);
return FALSE;
}
return TRUE;
}
int CSysApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
if(m_pConnection->State)
{
m_pConnection->Close();
m_pConnection=NULL;
}
return CWinApp::ExitInstance();
}
BOOL CSysApp::CreateDbFile(CString strFileName)
//创建数据库文件
{
try
{
m_pobjDaoDb->Create(strFileName);
}
catch(CDaoException *e)
{
char ch[255];
e->GetErrorMessage(ch,255);
e->Delete();
AfxMessageBox(ch);
return FALSE;
}
return TRUE;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询