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();

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。