sqlpr="insert into 人员 SELECT * FROM 人员 WHERE 姓名 is null";
//插入
m_pConnection->Execute(sqlpr.AllocSysString(),
&RecordsAffected,adCmdText);
sqlpr="SELECT * FROM 人员 WHERE 姓名 is null";
//执行一条SQL语句,得到一个记录集
m_printPtr->Open(sqlpr.AllocSysString(),
m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);m_printPtr->Close();//此处报错"对象关闭时,不允许操作。"
//插入
m_pConnection->Execute(sqlpr.AllocSysString(),
&RecordsAffected,adCmdText);
sqlpr="SELECT * FROM 人员 WHERE 姓名 is null";
//执行一条SQL语句,得到一个记录集
m_printPtr->Open(sqlpr.AllocSysString(),
m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);m_printPtr->Close();//此处报错"对象关闭时,不允许操作。"
看你在m_printPtr->open()前加了
m_printPtr.CreateInstance(_uuidof(Recordset));没
我在连SQL 2005时把adOpenDynamic换成adOpenStatic才好使。
如果用adOpenStatic,网络上没法同时看到你的更新!
我在连上SQL 2005后,执行你记录集部分代码是可行的(保证之前Connection没有关闭),能得出记录集数,关闭操作也能进行。 m_printPtr->Open(sqlpr.AllocSysString(),
m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
long num=m_printPtr->GetRecordCount(); CString message;
message.Format("共有%d条记录",num);
MessageBox(NULL,message,"提示",NULL); m_printPtr->Close();
m_pConnection->Execute(sqlpr.AllocSysString(),
&RecordsAffected,adCmdText);
但它能成功执行。
m_pConnection->Execute(sqlpr.AllocSysString(),
&RecordsAffected,adCmdText);
这一句?