用ADO编程遇到问题,请高手指教!!

qiujoe 2000-04-21 11:13:00
加精
我用#import的方法进行ADO编程却无法进行编译,错误信息说是用mfc编程中不能包含window.h,我该怎么办?我想用MFC 编程
...全文
1009 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
bush 2000-11-30
  • 打赏
  • 举报
回复
老兄:我向你请教!我急需写一个ado和DATAGRID 的project ,我要实现的是add,delete和update ,直接操纵DATAGRID 的ROW 和CEL,贴一段源码吧!!很急得!
halbert 2000-11-22
  • 打赏
  • 举报
回复
关于vc++ 的ado 编程
atdafx.h
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF", "adoEOF")

BOOL CGetemailApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox("ole 出错");
return FALSE;
}
::CoInitialize( NULL );
}
int CGetemailApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
::CoUninitialize();
return CWinApp::ExitInstance();
}

bool getrecordset()
{
char SqlStr[255],account[50];
char Error[500];
char putfilestr[300];
long recordnum;
m_pConnection = NULL;
m_pRecordset = NULL;
_variant_t TheEmail,ThePhone_office,TheAccount,TheUser_id;
char strEmail[50],strPhone_offiece[50],strAccount[50],strUser_id[50];
if(!OpenFileForReadWrite())
return ;
try{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
recordnum=m_pConnection->Open("DSN=stat","test","test",-1);
sprintf(putfilestr,"%20s %30s %40s %30s\n","用户编码","用户帐号","用户Email","用户办公电话");
fwrite(putfilestr,strlen(putfilestr),1,fpout);
while(!feof(fpin))
{
fscanf(fpin,"%s",account);
//sprintf(SqlStr,"select a.user_id,a.account, b.email,b.phone_office from userbasicinfo a,usercontactinfo b where a.account='%s' and b.user_id=a.user_id",account);
strcpy(SqlStr,"select * from region");
recordnum=m_pRecordset->Open(SqlStr,m_pConnection.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
//用 recordnum=m_pRecordset->Open(SqlStr,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
// 也出错
recordnum=m_pRecordset->adoEOF;
//执行到此出错,为何。跳到catch(...)
if(!m_pRecordset->adoEOF)
{
TheUser_id=m_pRecordset->GetCollect("user_id");

TheAccount=m_pRecordset->GetCollect("account");
TheEmail=m_pRecordset->GetCollect("email");
ThePhone_office=m_pRecordset->GetCollect("phone_office");
sprintf(putfilestr,"%20s %30s %40s %30s\n",TheUser_id.bstrVal,TheAccount.bstrVal,TheEmail.bstrVal,ThePhone_office.bstrVal);
fwrite(putfilestr,strlen(putfilestr),1,fpout);
}//end if
m_pRecordset->Close();
}//end while
}//end try
catch(_com_error *e)
{

//CString Error = e->ErrorMessage();
//char Error[500];
strcpy(Error , (char*)e->Description());
AfxMessageBox(e->ErrorMessage());
}
catch(_com_error e)
{

//CString Error = e->ErrorMessage();
strcpy(Error , (char*)e.Description());
//AfxMessageBox(e->ErrorMessage());
AfxMessageBox(Error);
}
catch(...)
{
AfxMessageBox("ado 出错");
}

m_pRecordset->Close();;
m_pConnection->Close();
m_pConnection->Release();
CloseAllFile();
}
// 执行到recordnum=m_pRecordset->adoEOF; 出错 为何
// 请那位大侠指点

mywater 2000-10-17
  • 打赏
  • 举报
回复
去掉警告,请引用ADO2.0以上版本
#import "c:\program files\common files\system\ado\msado20.tlb"......


qiujoe 2000-06-05
  • 打赏
  • 举报
回复
我已经解决了,谢谢各位!
ljw 2000-05-23
  • 打赏
  • 举报
回复
我也遇到此问题,按照书上做也不对,那位高手可以解决ADO数据库查询的问题?
qiujoe 2000-05-05
  • 打赏
  • 举报
回复
再请教一下kuitor and zzh
为什么有时在调用m_pConnection.CreateInstance(__uuidof(Connection));会失败???
qiujoe 2000-05-03
  • 打赏
  • 举报
回复
to speed and axiong:
我也没解决warning的问题。我也在等
speed 2000-05-02
  • 打赏
  • 举报
回复
qiujoe你的问题我也遇到了,能否也给我一个例子。谢谢。
top_cmy@263.net
Axiong 2000-05-02
  • 打赏
  • 举报
回复
qiujoe你搞好了,能不能给我一个最简单的sample呢。
这个问题烦了我好久了。 真心的感谢
wishful@163.net
qiujoe 2000-05-02
  • 打赏
  • 举报
回复
谁告诉我答案啊,我就可以给分了
qiujoe 2000-04-26
  • 打赏
  • 举报
回复
可是总不舒服啊,怎么可以去掉这个warning??
huitor 2000-04-22
  • 打赏
  • 举报
回复
是一个枚举值的问题,我也遇到了,但不影响使用
zzh 2000-04-21
  • 打赏
  • 举报
回复
第一步是引入ADO库文件,用如下所示语句
#import "c:\program files\common files\system\ado\msado15.dll"
第二步 初始化OLE/COM库环境 在InitInstance()中用
if(!AfxOleInit())
{
AfxMessageBox("OLE初始化出错!");
return FALSE;
}
第三步 使用ADO接口
ADO库包含三个基本接口:
__ConnectionPtr接口、
__CommandPtr接口和、
__RecordsetPtr接口
具体情况可以查看MSDN的帮助,在VC知识库里也有一遍文章介绍ADO编程
qiujoe 2000-04-21
  • 打赏
  • 举报
回复
谢谢!!error是消除了可是还有一个warning怎么办??为什么会有这个 warning??
telan 2000-04-21
  • 打赏
  • 举报
回复
应该是文件的先后顺序问题,你把
#import ....

放到stdafx.h文件的最后看看。
qiujoe 2000-04-21
  • 打赏
  • 举报
回复

谢谢 zzh的回答,我是这么做的
在stdafx.h中引入
#import "c:\program files\common files\system\ado\msado15.dll"\
no_namespace\
rename("EOF","adoEOF")
在CNorthwindApp::INitInstance()中使用了AfxOleInit();
可出现如下错误:

compiling...
StdAfx.cpp
f:\vc\northwind\debug\msado15.tlh(403) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
d:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
Error executing cl.exe.

northwind.exe - 1 error(s), 1 warning(s)

我有什么不对的吗?请各位大侠指正!!

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧