vc++6.0使用ADO连接数据库SqlServer2000的问题

luyinglply luyinglply 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
还是那个错误

vc++6.0使用ADO连接SqlServer2000数据库 然后把结果放在 CListBox控件里(m_Grid是CListBox的变量)
结果没有反应啊 也不知道哪里出了问题 各位 帮我看看啊
我建了一个对话框的mfc小程序
在app类的BOOL CAODcomApp::InitInstance()里写了

BOOL CAODcomApp::InitInstance()
{
AfxEnableControlContainer();

//--初始化com、ole
BOOL AFXAPI AfxOleInit();

if (!AfxOleInit())
{
AfxMessageBox("ole、com失败");

}
_RecordsetPtr m_pRecordset;
_ConnectionP tr m_pConntion;

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CAODcomDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();


if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.




HRESULT hr;

hr=m_pConntion.CreateInstance("Connection");

if (!SUCCEEDED(hr))
{
AfxMessageBox("m_pConntion连接失败");

}

//hr=m_pRecordset.CreateInstance(__uuidof(Recordset));
hr=m_pRecordset.CreateInstance("ADODB.Recordset");
if (!SUCCEEDED(hr))
{
AfxMessageBox("m_pConntion连接失败");

}

try
{

m_pConntion->ConnectionString="Provider=SQLOLEDB.1;Password=a1b2c3;User ID=rlsf;Initial Catalog=rlsf;DataSoure=(PC-20100311UUGX)";//本机可以如此表示。

CString strText="Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=rlsf;Initial Catalog=rlsf";

m_pConntion->Open((_bstr_t)strText,"","",adConnectUnspecified);


// _variant_t ra;
m_pRecordset=m_pConntion->Execute("select * FROM JCSJ_Czy",NULL,adCmdText);

//while(!m_pRecordset->rsEOF)
for(int i=0;i<=1;i++)
{
//dlg.m_Grid->AddString((_bstr_t)m_pRecordset->GetCollect("dwbm"));

dlg.m_Grid.InsertItem(0,"");
dlg.m_Grid.SetItemText(0,0,(char*)(_bstr_t)m_pRecordset->GetCollect("dwbm"));
//dlg.m_Grid.Update(false);
m_pRecordset->MoveNext();
}



/*m_pRecordset->AddNew();
m_pRecordset->PutCollect("dwbm","08");
m_pRecordset->PutCollect("bm","23");
m_pRecordset->PutCollect("czy","cccc");
m_pRecordset->Update();*/


m_pRecordset->Close();
m_pConntion->Close();
m_pRecordset.Release();
m_pConntion.Release();
CoUninitialize();
}
catch(_com_error e)
{
//AfxMessageBox("failed to read from the database");
CString str = e.ErrorMessage();
TRACE(str);

}



return FALSE;
}

其中//while(!m_pRecordset->rsEOF) 不好用 rsEOF不对 这句话是什么意思啊 我用for循环代替了

但是 一点没有反应 也不报错
...全文

相关推荐

用vc++6.0和SQLSEVER2000开发客户资源管理系统

**连接数据库**:在VC++ 6.0中使用ODBC(Open Database Connectivity)或ADO(ActiveX Data Objects)建立与SQL Server的连接,以便应用程序能够读写数据库

lichunming83

使用ADO技术连接SQL数据库的详细实践指南

在这一章节中,我们将通过一个实例来深入了解如何使用ADO(ActiveX Data Objects)技术连接SQL数据库。本章旨在为IT专业人员提供一个简洁明了的示例,从而便于他们理解在应用程序中实现数据库连接的操作步骤。ActiveX Data Objects (ADO) 是一套面向对象的程序设计接口,用于从各种数据源中检索数据。它允许开发者编写能够访问电子邮件数据库、文件系统以及任何其他能够通过OLE DB提供数据的任何类型的数据库数据的应用程序。

薛迟

基于c++的大学生信息管理系统

《基于VC++的大学生信息管理系统的设计与实现》一文详细介绍了如何利用Visual C++ 6.0结合SQL Server 2000数据库技术来开发一款针对大学生信息管理的系统。

duzuojingtingshan

VB语言使用ADO连接、操作SQLServer数据库教程

在VB中,我们需要添加“Microsoft ADO Data Control 6.0 (SP6) (OLEDB)”部件,这个部件包含了Adodc数据控件,它是连接和操作数据库的关键。

weixin_38558186

(原创)PERL用ADO连接SQLSERVER2000

标题中的"(原创)PERL用ADO连接SQLSERVER2000"指的是使用Perl编程语言通过ActiveX Data Objects (ADO) 连接并操作Microsoft SQL Server

xuguangming168
评论 5
收藏 已收藏
分享
返回顶部
luyinglply
数据库 4,017 成员 39,805 内容