_RecordsetPtr pRecSet;
pRecSet.CreateInstance(__uuidof( Recordset));
pRecSet->CursorLocation = adUseClient;
CString strSql = "select distinct cc.*,c.constraint_type
from user_cons_columns cc,user_constraints  c 
where  c.constraint_name =cc.constraint_name  and  cc.table_name =upper
                        ('app_leave_item') order by cc.position";pRecSet->Open(_bstr_t(strSql), GetApp()->GetConn(), adOpenStatic, 
             adLockReadOnly,adCmdText);
pRecSet->AddRef();if(!(pRecSet->BOF && pRecSet->adoEOF))
{
    pRecSet->MoveFirst();
}_variant_t vTmp1;
while(!pRecSet->adoEOF)
{
    vTmp1 = m_pForeignRs->GetCollect("COLUMN_NAME");//为什么这里会出错????一运动到这里
     //就出现异常
   //其实我想要获取特定表外键和主键的字段名称,改如何做呢?
}
{

解决方案 »

  1.   

    select distinct cc.*,c.constraint_type
    from user_cons_columns cc,user_constraints  c 
    where  c.constraint_name =cc.constraint_name  and  cc.table_name =upper
                            ('app_leave_item') order by cc.position
    这样可以取出来,
    m_pForeignRs->GetCollect("COLUMN_NAME")是什么意思,怎么没有pRecSet了?
      

  2.   

    单独执行sql语句正常吗?
    加条异常处理语句:
    BEGIN
      pRecSet->CursorLocation = adUseClient;
      ...
    EXCEPTION 
      WHEN OTHERS THEN
        dbms_output.putline('Error Code:'||sqlcode||' ErroMsg:'||sqlerrm);
    END;
      

  3.   

    To waterfirer(水清):pRecSet那里我复制过来的时候错了,应该是pRecSet!!!
    To rolandzhang():单独执行是正常的!我在plsql执行出来的结果都对了,只是在程序里面不知道怎么获取外键和主键的字段名,一获取就出错!!!
      

  4.   

    取值的方法是什么?
    pRecSet->GetCollect("COLUMN_NAME")就是取COLUMN_NAME列的值吗?要是那样的话应该可以啊你换成select cc.COLUMN_NAME,c.constraint_type
    from user_cons_columns cc,user_constraints  c 
    where  c.constraint_name =cc.constraint_name  and  cc.table_name =upper
                            ('app_leave_item') order by cc.position
    试试
      

  5.   

    To waterfirer(水清):不行呀,如果换成你的说法,执行到pRecSet->Open(...)这里就出错了!!!!
      

  6.   

    你有没有把distinct 去了啊,我觉得这里distinct 是没什么用的,加上是会报错的难道没有COLUMN_NAME列?不会吧...
      

  7.   

    To waterfirer(水清):Open已经成功了,但是GetCollect("COLUMN_NAME")还是会出错呀!!其实我只要知道怎么获取这个值就行了,值是对了,但是拿读不出来,拿不出来啊!!怎么办????
    在plsql中已经看到结果是对的了,可就是读不出来???怎么办??
      

  8.   

    你用的什么语言?现在应该不是oracle的问题了,就看你用的pRecSet怎么把值取出来了。也许你该到对应的语言版去问。
      

  9.   

    应该不是语言问题吧?
    我其他地方的数据都通过GetCollect("")的方式去读的,为什么就这个地方不行的?
    还请指教指教指教!!!!谢谢
      

  10.   

    就是谈一个异常框出来,没有什么提示!!!
    反正就是执行这条语句GetCollect("COLUMN_NAME")的时候出错了。
      

  11.   

    那就不好分析了1、看看vTmp1是否定义了,和GetCollect("COLUMN_NAME")类型是否一样。
    2、把COLUMN_NAME换成TABLE_NAME或其他列看看能不能查出来?
    3、把select语句换成简单的查询语句(如select 1 from Dual),看看GetCollect能否取出来