// 刚开始项目里面给的是 存储过程,但是存储蛋疼之后错误定位在了sql语句上
// 这是一整块测试代码
// 问出在那个sql语句void CadoDemoDlg::OnBnClickedButton1()
{ _ConnectionPtr m_pConnection;
m_pConnection.CreateInstance( _uuidof(Connection) ); // 连接字符串
CString cstrSql =_T("Provider=OraOLEDB.Oracle.1;Password=fantuan;Persist Security Info=True;User ID=fantuan;Data Source=\"(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) )(CONNECT_DATA =(SID = ORCL)(SERVER = DEDICATED)))\""); HRESULT hr; // _uuidof 获得全局唯一标实符
hr = m_pConnection.CreateInstance(_uuidof(Connection));
try
{
if(SUCCEEDED(hr)){
m_pConnection->Open(_bstr_t(_variant_t(cstrSql)),(_bstr_t)_T(""),(_bstr_t)_T(""),adConnectUnspecified);
}
_RecordsetPtr m_pRecordSet;
m_pRecordSet.CreateInstance(_uuidof(Recordset));                // 问题就出现在这个地方,如果我执行 没有注释的一句,就可以正常查出数据
                // 如果我改成带有 sequence 的这句,程序就会出错 3092 好像语句错了一样
//CString csSql = CString(_T("SELECT SEQ_DEPARTMENT_NUM.CURRVAL+1 FROM DUAL"));
CString csSql = CString(_T("select * from tb_department")); if(m_pRecordSet->State == adStateOpen ){
m_pRecordSet->Close();
}

m_pRecordSet->Open(_variant_t(csSql),m_pConnection.GetInterfacePtr(),adOpenStatic,adLockPessimistic,adCmdText);

long rowCnt = m_pRecordSet->Fields->GetCount();
long iRow = 0; while ( !m_pRecordSet->adoEOF )
{
CString var;
for (iRow = 0; iRow < rowCnt; iRow++ )
{
var += LPCTSTR(_bstr_t(m_pRecordSet->GetCollect(_variant_t(iRow))));
}
m_pRecordSet->MoveNext();
AfxMessageBox(var);
}

}catch(_com_error &e){
CString errormessage = e.ErrorMessage();
AfxMessageBox(errormessage.GetBuffer(errormessage.GetLength()));//显示错误信息
}
}

解决方案 »

  1.   

    ADO助手测试下SQL。
      

  2.   


    好像问题出在了 数据库 跟 程序 数据不同步的问题。
    就是上面的测试代码,
    运行结果是对的,
    但是在 plsql里查询出来的就不一样,
    还是初试的数据,
    我在另一个帖子里 提了问题
    感谢版主的帮忙
      

  3.   


    好像问题出在了 数据库 跟 程序 数据不同步的问题。
    就是上面的测试代码,
    运行结果是对的,
    但是在 plsql里查询出来的就不一样,
    还是初试的数据,
    我在另一个帖子里 提了问题
    感谢版主的帮忙还有我刚才 引用错了...能不能帮我删掉...
      

  4.   

    没事,CSDN不提倡删帖,在ADO中操作也用事务试试。