首页 > 代码库 > vc中将access数据库表中的数据添加到一个ComboBox中,实现从数据库中添加ComboBox的属性
vc中将access数据库表中的数据添加到一个ComboBox中,实现从数据库中添加ComboBox的属性
#include "..\..\Common\IO\AppDirectoryUtil.h"
#include "..\..\Common\Database\DbConnection.h"
#include "..\..\Common\Database\DbCommand.h"
#include "..\..\Common\Database\DbDataReader.h"
static CString GetConnectionString()
{
CString mdbFileName = CAppDirectoryUtil::GetParentDirectory() + TEXT("\\biaozhun.mdb");
return TEXT("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") + mdbFileName;
}
BOOL CArxEllipsoidalhead::OnInitDialog()
{
CDbConnection con(GetConnectionString());
con.Open();
CString sql = TEXT("Select * From biaozhun Where ID > 0");
CDbCommand cmd(sql, &con);
CDbDataReader *pdr = cmd.ExecuteReader();
while(pdr->Read())
{
//long ID = (pdr)[TEXT("ID")].ToDouble();
CString biaozhun = (*pdr)[TEXT("biaozhun")].ToString();
// m_standard.AddString(pdr->operator [](TEXT("biaozhun")));
m_standard.AddString(biaozhun);
// dr->MoveNext();
// CString author = (*dr)[TEXT("Author")].ToString();
// CString press = (*dr)[TEXT("Press")].ToString();
// double price = (*dr)[TEXT("Price")].ToDouble();
//acutPrintf(TEXT("\nID:%d, biaozhun:%s"),ID,biaozhun);
}
pdr->Close();
con.Close();
vc中将access数据库表中的数据添加到一个ComboBox中,实现从数据库中添加ComboBox的属性