我使用ADO和DataGrid控件做数据库工程。
但是我不想使用DataGrid的数据源关联,希望通过程序代码的形式添加数据。
因为我的数据库中的某些字段需要处理后填充在不同的单元格中。
不知道怎样才能实现。
TrueDbGrid好像需要注册,所以没有采用。
大家提提意见!
但是我不想使用DataGrid的数据源关联,希望通过程序代码的形式添加数据。
因为我的数据库中的某些字段需要处理后填充在不同的单元格中。
不知道怎样才能实现。
TrueDbGrid好像需要注册,所以没有采用。
大家提提意见!
// set datasource of CDataGrid dynamically
void CDgDlg::OnOK()
{ //notes : call AfxOleInit in CXXApp::InitInstance()
// I also add a line in stdafx.h
//#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Provider=sqloledb;Data Source=Dell1;"
"Initial Catalog=testdb;User Id=sa;Password=;",
"", "", adConnectUnspecified);
pRst->Open(
"table1",
_variant_t((IDispatch *) pConn, true),
adOpenStatic,
adLockReadOnly,
adCmdTable);
//CDataGrid m_grid; is a member of CDgDlg.
m_grid.SetRefDataSource(pRst.Detach());
}
catch (_com_error &e)
{
char mybuf[10240];
wsprintf(mybuf,"Description = '%s'\n", (char*) e.Description());
AfxMessageBox(mybuf);
}
}
Using DBGrid in unbound mode
它使用的DAO
不知道有没有ADO的
和DataGrid可以互相换用吗?
m_DataGrid.SetRefSource((LPDISPATCH)m_pRecordset);