比如:
有数组A
A(0)(0)=1
A(0)(1)="james"
A(1)(0)=2
A(0)(1)="tom"我需要得到一个adodb.recordset对象,其内容为:fldID     fldName
--------------------
1         james
2         tom请提供实现源码,谢谢!
/////////////////////////
在VB中的实现:
大致如下:
Dim A(1, 1) As String
Dim Rs As New ADODB.Recordset
A(0, 0) = 1
A(0, 1) = "james"
A(1, 0) = 2
A(1, 1) = "tom"
Dim I As Integer
For I = 0 To UBound(A)
   Rs.Fields.Append A(I, 0), adVarChar, 50
Next IRs.Open
For I = 0 To UBound(A)
   Rs.AddNew
   Rs.Fields(I).Value = A(I, 1)
   Debug.Print Rs.Fields(I).Name
Next I///////////
VC中如何实现?

解决方案 »

  1.   

    See the link below, FYI: http://www.codeproject.com/database/#ADOTake care the type of ur date when u append
      

  2.   

    给你一个参考:#include <stdio.h>
    //#include <afxdisp.h>#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                      if (FAILED(_hr)) _com_issue_error(_hr); }#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
    #define UC (char *)
    struct InitOle {
        InitOle()  { ::CoInitialize(NULL); }
        ~InitOle() { ::CoUninitialize();   }
    } _init_InitOle_;       // Global Instance to force load/unload of OLEvoid main(){    _RecordsetPtr   spRS;
        _RecordsetPtr   spRSCopy;
        _ConnectionPtr  spCON;
        try{
            CREATEiNSTANCE(spCON,Connection);
            spCON->ConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Index.mdb;"
                                      L"Persist Security Info=False"; 
            spCON->Open( "", "", "", -1 );
            CREATEiNSTANCE(spRS,Recordset) 
            spRS->PutRefActiveConnection( spCON );
            spRS->Open("select STATIONID,STATNAME from Station", vtMissing, adOpenKeyset,
                        adLockBatchOptimistic, adCmdUnspecified);        CREATEiNSTANCE(spRSCopy,Recordset) 
            spRSCopy->PutRefActiveConnection( spCON );
            spRSCopy->Open("select STATIONID,STATNAME from Copy", vtMissing, adOpenKeyset,
                        adLockOptimistic, adCmdUnspecified);
            
            while(spRS->adoEOF == false){
                printf("StationID = %s  StationName = %s \n", UC _bstr_t(RsITEM(spRS,"STATIONID")),
                                                     UC _bstr_t(RsITEM(spRS,"STATNAME")));
                spRSCopy->AddNew();
    RsITEM(spRSCopy,"STATIONID") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATIONID")));
    RsITEM(spRSCopy,"STATNAME") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATNAME"))); spRSCopy->Update();
    spRS->MoveNext();
            }
            spRS->Close();
    spRSCopy->Close();
            spCON->Close();
            
        }
        catch( _com_error &e){
            _bstr_t bstrSource(e.Source());
            _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ") 
                + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ") 
                + _bstr_t(e.Description());
            
            MessageBox(0,bs,bstrSource, MB_OK);
        }           
    }
    #undef UC
      

  3.   

    关键是recordset需要open。他是需要参数的。怎么办?