ADO 使用游标问题 默认的ADO连接游标不支持MOVELAST在对记录集进行MOVELAST的时候出现错误谁给一段让记录集支持MOVELAST的代码?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CToolLibrary ToolLib; ToolLib.OpenConnection();////程序执行到这三行的时候出现错误,这三行程序该放在那里来让记录集支持游标MOVELAST?// ToolLib.m_pConnection->CursorLocation = adUseClient; ToolLib.m_pRecordset->CursorLocation = adUseClient; ToolLib.m_pRecordset->CursorType = adOpenKeyset; _bstr_t Command = "select * from ddflml"; _variant_t RecordsAffected; ToolLib.m_pRecordset = ToolLib.m_pConnection->Execute(Command,&RecordsAffected,adCmdText); *****************************************************************BOOL CToolLibrary::OpenConnection(){ HRESULT hr; try { hr = m_pConnection.CreateInstance(__uuidof(Connection));///创建Connection对象 if(SUCCEEDED(hr)) { char buffer[128]; ZeroMemory(buffer,128); CString FilePath = MakeCurrentPath(); ::GetPrivateProfileString("database","Address",NULL,buffer,128,FilePath); CString szAddress = buffer; ZeroMemory(buffer,128); ::GetPrivateProfileString("database","UserName",NULL,buffer,128,FilePath); CString szUserName = buffer; ZeroMemory(buffer,128); ::GetPrivateProfileString("database","Password",NULL,buffer,128,FilePath); CString strCode = RestoreCode(buffer); CString szPassword = DecryptDes(strCode); _bstr_t DataString = "Provider=SQLOLEDB;SERVER="; _bstr_t temp = _bstr_t(szAddress); DataString += temp; DataString += ";DATABASE=arch;UID="; DataString += _bstr_t(szUserName); DataString += "; PWD="; temp=_bstr_t(szPassword); DataString += temp; hr = m_pConnection->Open(DataString,"","",adModeUnknown); } } catch(_com_error e)///捕捉异常 { CString errormessage; errormessage.Format("连接数据库失败!程序即将退出,请联系系统管理员!\r\n错误信息:%s",e.ErrorMessage()); ::MessageBox(NULL,errormessage,"错误",MB_ICONWARNING); ExitProcess(1); } return TRUE;} 把这三行程序放在和数据库建立连接之前也会出现出错误 ToolLib.m_pConnection->CursorLocation = adUseClient; ToolLib.m_pRecordset->CursorLocation = adUseClient; ToolLib.m_pRecordset->CursorType = adOpenKeyset; 代码太长,没时间看不过movelast经常用,没发现什么问题参考一下这个http://www.vckbase.com/document/viewdoc.asp?id=215 在Recordset的open方法中著名游标的使用权限,查msdn呀 m_connection是否为空?可有判断? 在一个类中调用另一个类de函数de方法 _stdcall与_cdecl 怎样调用? 数据库查询的问题 关于CComCoClass::Error()的疑问 问怎么读源码? 有关链表的问题。 VC连接SQL2005数据库时报错 我看大家的提问多很厉害,我好象还是小学生水平, *.cnt是什么文件 CDockablePane在隐藏状态下如何关闭? 急救!!!!!!!!!! 菜单命令为什么执行两次?在线!
//程序执行到这三行的时候出现错误,这三行程序该放在那里来让记录集支持游标MOVELAST?
//
ToolLib.m_pConnection->CursorLocation = adUseClient;
ToolLib.m_pRecordset->CursorLocation = adUseClient;
ToolLib.m_pRecordset->CursorType = adOpenKeyset; _bstr_t Command = "select * from ddflml";
_variant_t RecordsAffected;
ToolLib.m_pRecordset = ToolLib.m_pConnection->Execute(Command,&RecordsAffected,adCmdText);
*****************************************************************
BOOL CToolLibrary::OpenConnection()
{
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance(__uuidof(Connection));///创建Connection对象
if(SUCCEEDED(hr))
{
char buffer[128];
ZeroMemory(buffer,128);
CString FilePath = MakeCurrentPath();
::GetPrivateProfileString("database","Address",NULL,buffer,128,FilePath);
CString szAddress = buffer;
ZeroMemory(buffer,128);
::GetPrivateProfileString("database","UserName",NULL,buffer,128,FilePath);
CString szUserName = buffer;
ZeroMemory(buffer,128);
::GetPrivateProfileString("database","Password",NULL,buffer,128,FilePath); CString strCode = RestoreCode(buffer);
CString szPassword = DecryptDes(strCode);
_bstr_t DataString = "Provider=SQLOLEDB;SERVER=";
_bstr_t temp = _bstr_t(szAddress);
DataString += temp;
DataString += ";DATABASE=arch;UID=";
DataString += _bstr_t(szUserName);
DataString += "; PWD=";
temp=_bstr_t(szPassword);
DataString += temp;
hr = m_pConnection->Open(DataString,"","",adModeUnknown);
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!程序即将退出,请联系系统管理员!\r\n错误信息:%s",e.ErrorMessage());
::MessageBox(NULL,errormessage,"错误",MB_ICONWARNING);
ExitProcess(1);
}
return TRUE;
}
把这三行程序放在和数据库建立连接之前也会出现出错误
ToolLib.m_pConnection->CursorLocation = adUseClient;
ToolLib.m_pRecordset->CursorLocation = adUseClient;
ToolLib.m_pRecordset->CursorType = adOpenKeyset;
不过movelast经常用,没发现什么问题
参考一下这个
http://www.vckbase.com/document/viewdoc.asp?id=215