資源簡介
數(shù)據(jù)庫類中的SQLServerDB是在原來SQL Server實例中修改的,實際上連接SQL Server和Access的區(qū)別僅在于連接字符串的不同,
連接SQL Server用:
sprintf(m_strCon,"Provider=SQLOLEDB;Server=%s;Database=%s;uid=%s;pwd=%s;",m_servername,m_database,m_username,m_password);
連接Access用:
sprintf(m_strCon,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;");

代碼片段和文件信息
//?DlgStudengListCtl.cpp?:?實現(xiàn)文件
//
#include?“stdafx.h“
#include?“MFCApp_DB001.h“
#include?“DlgStudengListCtl.h“
//?CDlgStudengListCtl?對話框
extern?CSQLServerDB?g_db;
IMPLEMENT_DYNAMIC(CDlgStudengListCtl?CDialog)
CDlgStudengListCtl::CDlgStudengListCtl(CWnd*?pParent?/*=NULL*/)
:?CDialog(CDlgStudengListCtl::IDD?pParent)
{
}
CDlgStudengListCtl::~CDlgStudengListCtl()
{
}
void?CDlgStudengListCtl::DoDataExchange(CDataExchange*?pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX?IDC_LIST1?m_ctlStudentList);
}
BEGIN_MESSAGE_MAP(CDlgStudengListCtl?CDialog)
ON_BN_CLICKED(IDC_BUTTON1?&CDlgStudengListCtl::OnBnClickedButton1)
END_MESSAGE_MAP()
//?CDlgStudengListCtl?消息處理程序
void?CDlgStudengListCtl::OnBnClickedButton1()
{
//?TODO:?在此添加控件通知處理程序代碼
}
BOOL?CDlgStudengListCtl::OnInitDialog()
{
CDialog::OnInitDialog();
//?TODO:??在此添加額外的初始化
//初始化列表控件
LONG?lstyle;
lstyle?=?GetWindowLong(m_ctlStudentList.m_hWnd?GWL_style);//獲取當前窗口style
lstyle?&=?~LVS_TYPEMASK;?//清除顯示方式位
lstyle?|=?LVS_REPORT;?//設(shè)置style
SetWindowLong(m_ctlStudentList.m_hWnd?GWL_style?lstyle);//設(shè)置style
DWORD?dwstyle?=?m_ctlStudentList.GetExtendedstyle();
dwstyle?|=?LVS_EX_FULLROWSELECT;//選中某行使整行高亮(只適用與report風格的listctrl)
dwstyle?|=?LVS_EX_GRIDLINES;//網(wǎng)格線(只適用與report風格的listctrl)
dwstyle?|=?LVS_EX_CHECKBOXES;//item前生成checkbox控件
m_ctlStudentList.SetExtendedstyle(dwstyle);?//設(shè)置擴展風格
//設(shè)置標題欄
m_ctlStudentList.InsertColumn(?0?“ID“?LVCFMT_LEFT?60?);//插入列
m_ctlStudentList.InsertColumn(?1?“NAME“?LVCFMT_LEFT?200?);
LoadDataFromDb();
return?TRUE;??//?return?TRUE?unless?you?set?the?focus?to?a?control
//?異常:?OCX?屬性頁應返回?FALSE
}
void?CDlgStudengListCtl::LoadDataFromDb()
{
if?(m_studentList.size()>0)
{
//清空vector中的數(shù)據(jù)
m_studentList.clear();
//清空列表控件中的內(nèi)容
m_ctlStudentList.DeleteAllItems();
}
_RecordsetPtr?pRec;
pRec?=?g_db.Query(“select?t_idnot_name?from?tb_test“);
_variant_t?t_idnot_name;
CString?csTxt;
while?(!pRec->EndOfFile)
{
CTbTest?test;
t_idno?=?pRec->GetCollect(“t_idno“);
t_name?=?pRec->GetCollect(“t_name“);
test.m_idno?=?atoi((char*)(_bstr_t)t_idno);
test.m_name?=?(char*)(_bstr_t)t_name;
csTxt.Format(“%d“test.m_idno);
int?nRow?=?m_ctlStudentList.InsertItem(0?csTxt);//插入行
csTxt.Format(“%s“test.m_name.c_str());
m_ctlStudentList.SetItemText(nRow?1?csTxt);//設(shè)置數(shù)據(jù)
m_studentList.push_back(test);
pRec->MoveNext();
//移到下一條記錄
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????902??2015-12-03?11:01??MFCApp_DB001.sln
????..A..H.?????12288??2015-12-04?10:14??MFCApp_DB001.suo
?????文件?????241664??2015-11-27?08:47??MFCApp_DB001\db.mdb
?????文件???????2659??2015-12-03?14:39??MFCApp_DB001\DlgStudengListCtl.cpp
?????文件????????650??2015-12-03?11:58??MFCApp_DB001\DlgStudengListCtl.h
?????文件???????1014??2015-12-03?14:09??MFCApp_DB001\DlgStudentAdd.cpp
?????文件????????449??2015-12-03?11:51??MFCApp_DB001\DlgStudentAdd.h
?????文件???????2807??2015-12-03?15:00??MFCApp_DB001\DlgStudentList.cpp
?????文件????????724??2015-12-03?14:48??MFCApp_DB001\DlgStudentList.h
?????文件?????536576??2008-04-14?20:00??MFCApp_DB001\dll\msado15.dll
?????文件???????5778??2015-11-26?14:43??MFCApp_DB001\MainFrm.cpp
?????文件????????996??2015-11-26?14:43??MFCApp_DB001\MainFrm.h
?????文件?????126380??2015-12-03?14:03??MFCApp_DB001\MFCApp_DB001.aps
?????文件???????4409??2015-12-03?09:41??MFCApp_DB001\MFCApp_DB001.cpp
?????文件????????672??2015-12-03?09:38??MFCApp_DB001\MFCApp_DB001.h
?????文件??????13153??2015-12-03?14:03??MFCApp_DB001\MFCApp_DB001.rc
?????文件???????6748??2015-12-03?11:01??MFCApp_DB001\MFCApp_DB001.vcproj
?????文件???????1407??2015-12-04?10:14??MFCApp_DB001\MFCApp_DB001.vcproj.203-1.Administrator.user
?????文件???????1408??2015-12-03?20:01??MFCApp_DB001\MFCApp_DB001.vcproj.Bob-PC.Bob.user
?????文件???????1130??2015-11-26?14:43??MFCApp_DB001\MFCApp_DB001Doc.cpp
?????文件????????584??2015-11-26?14:43??MFCApp_DB001\MFCApp_DB001Doc.h
?????文件???????2751??2015-12-03?11:06??MFCApp_DB001\MFCApp_DB001View.cpp
?????文件???????1253??2015-12-03?11:05??MFCApp_DB001\MFCApp_DB001View.h
?????文件???????3560??2015-11-26?14:43??MFCApp_DB001\ReadMe.txt
????.......?????67777??2007-11-28?16:21??MFCApp_DB001\res\MFCApp_DB001.ico
?????文件????????368??2015-11-26?14:43??MFCApp_DB001\res\MFCApp_DB001.rc2
????.......??????4710??2007-10-31?09:37??MFCApp_DB001\res\MFCApp_DB001Doc.ico
????.......??????1078??2003-07-24?09:52??MFCApp_DB001\res\Toolbar.bmp
????.......??????5816??2007-08-30?17:14??MFCApp_DB001\res\Toolbar256.bmp
?????文件???????1593??2015-12-03?11:04??MFCApp_DB001\resource.h
............此處省略14個文件信息
評論
共有 條評論