逍遥潘达(mpandar)ipanda.blog.chinaunix.net
mpandar
全部博文(45)
2012年(1)
2011年(25)
2010年(19)
rekken
yangpeng
丶lemona
monkely
CallAck
sanljd01
代码如诗
ClarePha
dreamtal
opkdong_
分类: C/C++
2010-12-23 10:57:15
#include <windows.h> #include <stdio.h> #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") int main(int argc, char* argv[]) { HRESULT hr = S_OK; try { CoInitialize(NULL); // Define string variables. _bstr_t strCnn("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=username;Password=passwd;Initial Catalog=database;Data Source=(local);Integrated Security=SSPI;"); _RecordsetPtr pRstAuthors = NULL; // Call Create instance to instantiate the Record set hr = pRstAuthors.CreateInstance(__uuidof(Recordset)); if(FAILED(hr)) { printf("Failed creating record set instance\n"); return 0; } //Open the Record set for getting records from Author table pRstAuthors->Open("SELECT Author_ID,username FROM Author",strCnn, adOpenStatic, adLockReadOnly,adCmdText); //Declare a variable of type _bstr_t _bstr_t valField1; int valField2; pRstAuthors->MoveFirst(); //Loop through the Record set if (!pRstAuthors->EndOfFile) { while(!pRstAuthors->EndOfFile) { valField1 = pRstAuthors->Fields->GetItem("username")->Value; valField2 = pRstAuthors->Fields->GetItem("Author_ID")->Value.intVal; printf("%d - %s\n",valField2,(LPCSTR)valField1); pRstAuthors->MoveNext(); } } } catch(_com_error & ce) { printf("Error:%s\n",ce.Description); } CoUninitialize(); return 0; }
上一篇:C语言中类型的自动转换
下一篇:关于switch的错误
登录 注册