1。用#import指令引入ADO类型库#import"c:\programfiles\commonfiles\system\ado\msado15.dll"no_namespacerename("EOF","adoEOF")2。初始化COM库AfxOleInit();///3。连接数据库HRESU...
1。用#import指令引入ADO类型库
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。初始化COM库
AfxOleInit();///
3。连接数据库
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sj.mdb","","",adModeUnknown);///连接数据库
///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51; }
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return FALSE;
}
4。执行SQL命令并向 cj 表的Txt字段添加 25 这个值。
_variant_t RecordsAffected;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pConnection->Execute("INSERT INTO cj(Txt) VALUES ('25')",&RecordsAffected,adCmdText);
编译没问题,运行错了
第4步应该怎么改啊?
编译没问题,运行出现这样this application has requested the Runtime to terminate it in an unusual way,please contact the application "s support team for more information,????这是什么原因?
展开