我用 Ado 执行查询操作select from * asg 没有问题,但是我想把查询的结果存入一张表中,执行select * int aaa from asg ,执行后,表可以创建,但是关闭数据库的时候总是报错,很是奇怪,请赐教。在线等待。

解决方案 »

  1.   

    你读出数据以后,执行SQL语句,一条一条的写进表中,不会出错的啊
      

  2.   

    m_pUserSet= new _RecordsetPtr;

    HRESULT hr=(*m_pUserSet).CreateInstance("ADODB.Recordset");
    if(hr!=S_OK) return false;
    try
    {
       m_adoDBConn.GetConnection()->GetInterfacePtr()->BeginTrans();
       (*m_pUserSet)->Open((_variant_t)"select * into aaa from asg",
    m_adoDBConn.GetConnection()->GetInterfacePtr(),
    adOpenDynamic, adLockOptimistic,adCmdText);
       (*m_pUserSet)->Close();//执行此句时出错,报称关闭操作时没有权限
       delete m_pUserSet;
       m_pUserSet=NULL;
                m_adoDBConn.CloseConnect();
    }
      

  3.   

    m_pUserSet= new _RecordsetPtr;//要去掉这一句

    HRESULT hr=(*m_pUserSet).CreateInstance("ADODB.Recordset");
             //改为 HRESULT hr=m_pUserSet.CreateInstance("ADODB.Recordset");
    if(hr!=S_OK) return false;
    try
    {    m_adoDBConn->GetInterfacePtr()->BeginTrans();
                 
                //m_pUserSet->Open((_variant_t)"select * into aaa from asg",
                     //...
       (*m_pUserSet)->Open((_variant_t)"select * into aaa from asg",
    m_adoDBConn.GetConnection()->GetInterfacePtr(),
    adOpenDynamic, adLockOptimistic,adCmdText);
                //m_pUserSet->Close();
       (*m_pUserSet)->Close();//执行此句时出错,报称关闭操作时没有权限
       
                delete m_pUserSet;//去掉
       m_pUserSet=NULL;  //去掉
                m_adoDBConn.CloseConnect();
    }
      

  4.   

    select * into aaa from asg
    你的这个操作并不返回结果集,所以你关闭的时候就出错了,
    我在你的另一个贴子中回复了,你查询到的结果已经存到一个表中了
    你可以使用m_pConnection->Execute()的方法
    ——————
    你可以拿这个SQL语句放到数据库中执行一遍,就会发现,并不返回结果集
      

  5.   

    可能你的数据库不支持select into或该语法不适合该数据库
      

  6.   

    不需要执行m_pUserSet->Close();
    因为你并没有打开一个记录集。
      

  7.   

    执行(*m_pUserSet)->Open((_variant_t)"select * into aaa from asg",
    m_adoDBConn.GetConnection()->GetInterfacePtr(),
    adOpenDynamic, adLockOptimistic,adCmdText);
    这一句,并没有真正“open”
    你可以判断一下此时m_pUserSetde 的状态;
    if(m_pUserSetde->State==adStateOpen)
    {
    }
    if(m_pUserSet->State==adStateClosed)
    {
    }
    ....
      

  8.   

    if(m_pUserSetde->State==adStateOpen)
    {
        m_pUserSet->Close();
    }