问题如题所述,大家能否提供下例子,我看了书上的例子,但运行不出来,我刚学数据库,对这方面还不熟,想找个例子来比较下。
解决方案 »
- MFC程序能否引用"Windows.h",其实放在“afxwin.h”后面就能编译
- 如何自绘任务栏的中间部分
- 谁用过NKD,我用它做C/S时,在传送大数据时,S端不响应!
- 怎样进行文件加密,在线等,一经解决立即结贴!!!!!
- 用VC7编写的程序如何放到只有操作系统的机器上使用(我已经编译成Release了,还是不行)
- ListView中,选择多项记录进行删除时,为什么会出错,请大虾帮忙!
- 五子棋代码哪里有?
- 在VC中如何运行DOS命令(14:00给分)
- ****关于CreateThread()函数问题*******唉,好头疼啊!!!!!!!!
- 文字录入
- VC++ ADO连接本地SQL数据库
- 谁有关于window gdi 的一些教程的资料?
{
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
try
{
pRecordset->Open("SELECT * FROM bbs",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
exit(0);
}
CString strTemp;
m_wndList.DeleteAllItems();
_variant_t var;
try
{
if(pRecordset->BOF)
AfxMessageBox("数据库为空!");
pRecordset->MoveLast();
while(!pRecordset->BOF)
{
var=pRecordset->GetCollect("Id");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="";
int nRow=m_wndList.InsertItem(0,strTemp);
var=pRecordset->GetCollect("Url");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="";
m_wndList.SetItemText(nRow,1,strTemp);
var=pRecordset->GetCollect("Type");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="";
m_wndList.SetItemText(nRow,2,strTemp);
var=pRecordset->GetCollect("UserName");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="未设置";
m_wndList.SetItemText(nRow,3,strTemp);
var=pRecordset->GetCollect("PassWord");
if(var.vt != VT_NULL) strTemp = "已设置";
else strTemp="未设置";
m_wndList.SetItemText(nRow,4,strTemp);
var=pRecordset->GetCollect("MaxUiD");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="自动判断";
if(strTemp=="0") strTemp="自动判断";
m_wndList.SetItemText(nRow,5,strTemp);
var=pRecordset->GetCollect("Interval");
if(var.vt != VT_NULL) strTemp = (LPCSTR)_bstr_t(var);
else strTemp="自动判断";
if(strTemp=="0") strTemp="自动判断";
m_wndList.SetItemText(nRow,6,strTemp);
var=pRecordset->GetCollect("IsChosen");
if(var.intVal==1)
m_wndList.SetItemText(nRow,7,"√");
else
m_wndList.SetItemText(nRow,7,"×");
pRecordset->MovePrevious();
}
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
if(pRecordset->State)
pRecordset->Close();
pRecordset=NULL;
}
AfxMessageBox("数据库为空!");后加return;
_ConnectionPtr m_pConnection是C**App的成员变量BOOL CQunFaApp::InitInstance()
{ m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败!");
exit(0);
}
}