请问VC控制台程序如何读取INI文件和操作SQL Server数据库,有没有相关的例程。

解决方案 »

  1.   

    操作ini文件:
    GetPrivateProfileInt
    GetPrivateProfileSection 
    GetPrivateProfileSectionNames 
    GetPrivateProfileString 
    GetPrivateProfileStruct 
    GetProfileInt 
    GetProfileSection 
    GetProfileString 
    WritePrivateProfileSection 
    WritePrivateProfileString 
    WritePrivateProfileStruct 
    WriteProfileSection 
    WriteProfileString
      

  2.   

    #include <sqlfront.h>
    #include <sqldb.h>  
    dbsqlexec (SQLString)
      

  3.   

    #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
      

  4.   

    不通过DSN对SQL SERVER数据库进行连接:m_pConnection->
    Open(
    "driver={SQLServer};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown
    );
      

  5.   

    操作ini和sql 数据库都有很多例子的,楼主可以自己找找
      

  6.   

    操作ini程序的 有很多别人实现的类的   ini文件读写代码  http://www.vckbase.com/code/downcode.asp?id=2609
     读写ini的C++类  http://www.vckbase.com/code/downcode.asp?id=2462
      

  7.   

    超作sql 数据库的例子就更多了拉