try
{
m_pRecordset->Open("SELECT * FROM users",
theApp.m_pConnection.GetInterfacePtr(),// 请问那个theApp是干麻的?为什么这代码
在事例中可以运行,而我复制这段代码后无法运行?
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} try
{
m_pRecordset->Open("SELECT * FROM users", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} _variant_t var;
CString strName,strAge;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
} // 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("Name");
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("Age");
if(var.vt != VT_NULL)
strAge = (LPCSTR)_bstr_t(var); m_AccessList.AddString( strName + " --> "+strAge ); m_pRecordset->MoveNext();
} m_AccessList.SetCurSel(0);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}错误内容:
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2065: 'theApp' : undeclared identifier
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2228: left of '.m_pConnection' must have class/struct/union type
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2228: left of '.GetInterfacePtr' must have class/struct/union type
===============
请问那个theApp是干麻的?为什么这代码在vc知识库(直接通过的AOD访问数据库)事例代码中可以运行,而我复制这段代码后无法运行?
{
m_pRecordset->Open("SELECT * FROM users",
theApp.m_pConnection.GetInterfacePtr(),// 请问那个theApp是干麻的?为什么这代码
在事例中可以运行,而我复制这段代码后无法运行?
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} try
{
m_pRecordset->Open("SELECT * FROM users", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} _variant_t var;
CString strName,strAge;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
} // 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("Name");
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("Age");
if(var.vt != VT_NULL)
strAge = (LPCSTR)_bstr_t(var); m_AccessList.AddString( strName + " --> "+strAge ); m_pRecordset->MoveNext();
} m_AccessList.SetCurSel(0);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}错误内容:
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2065: 'theApp' : undeclared identifier
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2228: left of '.m_pConnection' must have class/struct/union type
F:\vc\myapp\mdb5\mdb5Dlg.cpp(185) : error C2228: left of '.GetInterfacePtr' must have class/struct/union type
===============
请问那个theApp是干麻的?为什么这代码在vc知识库(直接通过的AOD访问数据库)事例代码中可以运行,而我复制这段代码后无法运行?
解决方案 »
- mfc在本机存储大量数据
- MessageBox的返回值是什么,怎么获得它的返回值呢?
- 如何编辑一个窗口客户区view中的内容
- 求助,在网页中调用activex控件,用世纪之窗浏览器调用后关闭时不出现错误,可是用ie6调用后关闭网页时出现错误,请问是怎么回事如何解决?
- 向当前光标位置的句柄发送消息
- 先运行对话框再运行菜单的问题
- 一个自绘Listview的问题
- 请教如何在DLL内设置一个时钟?
- 关于用ADO中RecordSet->RecordCount得到的是-1而不是实际记录数问题?
- 将代码从VC6迁移到VC2008后的宏定义报错
- 在 dll 中打开一个对话框,请问这个对话框我可以任意操作吗? 就象是通过向导生成的对话框一样吗?
- 请教高手: 向RichEdit控件发送SET_TEXT消息往里写内容的问题!有的能写进去内容,有的却写不进去?
extern CXXXApp theApp;
XXX为你的项目名
我的项目名为:mdb5
我在mdb5dlg.h中添加 extern cmdb5App theApp;
显示:
f:\vc\myapp\mdb5\mdb5dlg.h(14) : error C2146: syntax error : missing ';' before identifier 'theApp'
f:\vc\myapp\mdb5\mdb5dlg.h(14) : fatal error C1004: unexpected end of file found
Generating Code...
Error executing cl.exe.
mdb5.exe - 4 error(s), 0 warning(s)
我能不能吧原代码发上来,你帮我看一下那的问题?
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。app文件的InitInstance中加入
if(S_OK!=OleInitialize(NULL))
{
AfxMessageBox("初始化COM组件库错误");
}
下面就是数据库操作
_ConnectionPtr pConn;
_RecordsetPtr pRs;
CString strSQL;
pConn.CreateInstance(__uuidof(Connection));
pConn->CursorLocation=adUseClient;
strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";
pConn->Open(_bstr_t(strSQL),"","",-1);
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation=adUseClient;
pRs->PutActiveConnection(pConn.GetInterfacePtr());
pRs1.CreateInstance(__uuidof(Recordset));
pRs1->CursorLocation=adUseClient;
pRs1->PutActiveConnection(pConn.GetInterfacePtr()); strSQL="select * from catalog order by cataid";
pRs->Open(_bstr_t(strSQL),vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText);
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。app文件的InitInstance中加入
if(S_OK!=OleInitialize(NULL))
{
AfxMessageBox("初始化COM组件库错误");
}
================
上面两行我已经加入过,还有我连接的是access,不是sqlserver.
请问该怎么办?
extern CMdb5App theApp; // 在此引用应用类中的theApp来获取库连接指针
///////////////////////////////
我在mdb5dlg.cpp文件中加入上面一句话后,能编译成功,但不能运行?请问是什么原因?加在下面句的后面
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////
这个是我错误工程的原代码,没加入msado15.dll这个文件。那位好朋友帮我看一下错误在那?
http://www.vchelp.net/ASP/cdf_pic/200410/subject_1_119572.rar
但也是能编译成功,但不能运行!
no_namespace \
rename ("EOF", "adoEOF")
不要用#include <msadl15.dll>
然后再.cpp加extern CMdb5App theApp;就可以了
我用的是#import "msado15.dll" no_namespace rename ("EOF", "adoEOF")
我的msado15.dll放在项目文件下。
extern CMdb5App theApp;我也加入了,问题依旧。
要不把你编译成功的文件打包传给我?
这是我那边错误的图片。
http://asp5.6to23.com/scm110/test/error.gif
http://www.vchelp.net/cndevforum/subject_view.asp?subject_id=119572&forum_id=79
也是可以编译成功的。
晕,我总于看到你哪里出错了,你的
m_pRecordset->Open("SELECT * FROM user", theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
里面没有“name”和“age”字段,当然运行到读数据表的时候就错了啊。
你改成
m_pRecordset->Open("SELECT * FROM Demotable", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
就可以了,“name”和“age”字段在你的Demotable表。
hoho,你复制粘贴的时候也太大意了。
是我太粗心了!也许是因为我的mdb里面有两个表格我都被他们搞糊涂了-_-,呵呵。
以后有问题想你继续向你请教:-)