1,理论上支持任何数据库,以Acess为例,结构如下图
body.clientHeight)this.width=body.clientHeight" src="http://www.338888.com/VCShare/images/upfile/2004615211236.jpg" onmousewheel="return yuzi_img(event,this)"
2,相关信息记录在ini或注册表中,其结构为:
[数据源]
DSN=TestODBC
UID=admin
PWD=
3,动态绑定一个类,更改GetDefaultConnect
CString CCharacterSet::GetDefaultConnect()
{
CSetODBC dlg;
CString strConnect = "ODBC;" + dlg.GetConnectStr();
return _T(strConnect);//动态取得ODBC
//return _T("ODBC;DSN=TestODBC");
}
4,使用
void CTestODBCDlg::OnRecordset()
{
CCharacterSet rs;
CSetODBC dlg;
rs.Open(dlg.GetWriteDBStyle());
{//增加记录
rs.AddNew();
rs.m_Name = "典韦";
rs.m_Age= 60;
rs.m_country = "魏";
rs.Update();
}
{//修改记录
rs.MoveFirst();
while(!rs.IsEOF())
{
if("典韦" == rs.m_Name)
{
rs.Edit();
rs.m_Age = 59;
rs.Update();
}
rs.MoveNext();
}
}
{//删除记录
rs.MoveFirst();
while(!rs.IsEOF())
{
if("典韦" == rs.m_Name)
{
rs.Delete();
rs.Requery();
}
rs.MoveNext();
}
}
{//显示所有记录
rs.MoveFirst();
CString strOutPut;
while(!rs.IsEOF())
{
CString strRecord;
rs.m_Name.TrimLeft();
rs.m_Name.TrimRight();
rs.m_country.TrimLeft();
rs.m_country.TrimRight();
strRecord.Format("Name = %s \tCountry = %s \tAge = %d \n",rs.m_Name,rs.m_country,rs.m_Age);
strOutPut += strRecord ;
rs.MoveNext();
}
AfxMessageBox(strOutPut);
}
rs.Close();
}