use wxwidgets and ado in vc.net

类别:编程语言 点击:0 评论:0 推荐:
use wxwidgets and ado in vc.net

用mfc总是让人觉得别扭,
比较一下第三方的图形库,wxwidgets不错
要操作数据库,当然是用ado库
我编译好wxwidgets后,在example里找到grid的example开刀
把那些杂七杂八的东西删了
#include <comdef.h>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "EndOfFile")
using namespace ADODB;
再GridFrame::GridFrame()中添加
CoInitialize(0);
HRESULT hr;
_ConnectionPtr myConnection;
myConnection.CreateInstance(__uuidofConnection));
hr=myConnection->Open("Provider=SQLOLEDB.1;SERVER=ZZU- CZX;DATABASE=friend","sa","letmein",0);
_CommandPtr pCommand;
pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection=myConnection; pCommand->CommandText="select * from t1";
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset->CursorLocation=adUseClient;
pRecordset->Open((IDispatch*)pCommand,vtMissing,adOpenStatic,adLockBatchOptimistic,adCmdUnknown);
找了个合适的地方添加
_variant_t data;
grid = new wxGrid( this,wxID_ANY,wxPoint( 0, 0 ));
grid->CreateGrid( pRecordset->GetRecordCount(), 3 );
for (int row = 0; row <>GetRows(); row++)
{
data=pRecordset->GetCollect("name");
grid->SetCellValue(row,0,(wxString)_bstr_t(data));
pRecordset->MoveNext();
}
大概就是这样,总之我觉得理解了就很简单,而且用起来也方便

本文地址:http://com.8s8s.com/it/it22307.htm