The rowset is not bookmarkable"错误

用一个ADO+DATAGRID写的程序,编译正常.运行时出现"rowset is not bookmarkable",查了函数的调用和类型.都没有问题.
搜索了下.原来是游标的问题.

在ADOConn类的中GetRecordset方法中增加一句m_pRecordset->CursorLocation=adUseClient;

即:
// 执行查询
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
try
{
// 连接数据库,如果Connection对象为空,则重新连接数据库
if(m_pConnection==NULL)
OnInitADOConn();
// 创建记录集对象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//增加这一句.
m_pRecordset->CursorLocation=adUseClient; //游标的位置出现.不加这句会出现The rowset is not //bookmarkable运行错误

// 取得表中的记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
// 返回记录集
return m_pRecordset;
}
调用的方法是:



BOOL CDataGridDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//原代码省略

// TODO: Add extra initialization here
//************************************************************
ADOConn m_ado;
_bstr_t vSql="select * from users";
_RecordsetPtr m_pRecordset;


m_ado.OnInitADOConn();
m_pRecordset=m_ado.GetRecordSet(vSql);

m_datagrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);//m_datagrid为DataGrid控件的变量.

//************************************************************

return TRUE; // return TRUE unless you set the focus to a control
}

你可能感兴趣的:(bookmark)