试试QT框架。
QT框架是什么?
@欧阳秦穆: http://baike.baidu.com/view/23681.htm。这个资料对你了解QT很有帮助。
@樰崧澍: 后面有个小写字母m,网页编辑器没把后面的字母算在链接内,请留意。
@崨雁嫀筝:
#include "stdafx.h" #include <icrsint.h> #include<iostream> #include<iomanip> #include <string> using namespace std; #import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")//#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile") // void main() { CoInitialize(NULL); _ConnectionPtr sqlSp; HRESULT hr=sqlSp.CreateInstance(_uuidof(Connection)); if(FAILED(hr)) { cout<<"_ConnectionPtr对象指针实例化失败!!!"<<endl; return ; } else { try { _bstr_t strConnect="Driver={sql server};server=10.36.246.219,3000;uid=hhfoxconnFSC;pwd=amebiz-hhfoxconnFSC-2013;database=Mytest;";//自己的數據庫 sqlSp->Open(strConnect,"","",adModeUnknown); } catch(_com_error &e) { cout<<e.Description()<<endl; } _RecordsetPtr m_pRecordset; if(FAILED(m_pRecordset.CreateInstance( _uuidof( Recordset )))) { cout<<"记录集对象指针实例化失败!"<<endl; return; } try { m_pRecordset->Open("SELECT * from s",(IDispatch*)sqlSp,adOpenDynamic,adLockOptimistic, adCmdText); //m_pRecordset->Open("SELECT s#=case when s# is null then '' else s# end ,c# ,grade,sex from sc",(IDispatch*)sqlSp,adOpenDynamic,adLockOptimistic, adCmdText); } catch (_com_error &e) { cout << e.Description()<<endl; } try { m_pRecordset->MoveFirst(); while(!m_pRecordset->adoEOF) { string insertTime=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("s#"))->Value);//從表中某個欄位下查詢數據 string insertTime2=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("sname"))->Value);//從表中某個欄位下查詢數據 string insertTime3=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("age"))->Value);//從表中某個欄位下查詢數據 string insertTime4=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("sex"))->Value);//從表中某個欄位下查詢數據 cout<<insertTime<<insertTime2<<insertTime3<<insertTime4<<endl; m_pRecordset->MoveNext(); } } catch (_com_error &e) { cout << e.Description()<<endl; } //0刪除一條數據 try { _variant_t RecordsAffected; //m_pRecordset->Open("delete from sc where grade=51",(IDispatch*)sqlSp,adOpenDynamic,adLockOptimistic, adCmdText); sqlSp->Execute("delete from sc where grade=51",&RecordsAffected,adCmdText); } catch (_com_error &e) { cout << e.Description()<<endl; } sqlSp->Close();//(strConnect,"","",adModeUnknown); //m_pRecordset->Close(); // 注意!!!不要多次关闭!!!!!!!!!!!! m_pRecordset =NULL; sqlSp=NULL; CoInitialize(NULL); } system("pause"); }
剛剛回覆的太差勁,重新回覆
工程类型是仅是表象。。
把操作数据库的代码封装起来,与控件或者说界面分享开来,就可以在任何地方使用了。包括界面和控制台。