#include <stdio.h> 
#include <windows.h>
#include <string.h>

#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")   //引入ADO库

int main(void)
{
    _ConnectionPtr m_pConnection=NULL;
    CoInitialize(NULL);  //初始化com库
    HRESULT hr = m_pConnection.CreateInstance("ADODB.Connection");    //创建Connection对象
    if(SUCCEEDED(hr))  //创建数据库connection对象成功
    {
		_bstr_t strConnect = "Provider = SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info =false;Initial Catalog = student;Data Source =WP";
        hr = m_pConnection->Open(strConnect,"","",adModeUnknown);
        if(SUCCEEDED(hr))   //连接数据库字符串成功
        {
	        _RecordsetPtr MySet;
            MySet.CreateInstance(__uuidof(Recordset));
            MySet->Open("SELECT * FROM base",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
            _variant_t Holder;
            while(!MySet->adoEOF)
            {
                Holder = MySet->GetCollect("xm");
                if(Holder.vt!=VT_NULL)
                    printf("%s\n",(char*)_bstr_t(Holder));
                MySet->MoveNext();
            }
        }
	}
    return 0;
}