各位大虾,这是我在编写VC++数据库编程中出现的问题,不知那位大虾,能给小的一些意见,指导指导,谢谢!为什么我在程序中用预编译指令#import,程序会出错,这个提示是什么问题?怎么改?illegal escape sequence什么意思?
//
//通过在程序中使用预编译指令#import来告诉编译器
//将此指令中指定的动态链接库引入工程中,
//并从动态链接库中取出其中的对象和信息,
//产生msado15.tlh和ado15.tli两个头文件来定义ADO库
//
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")--------------------Configuration: YDMS - Win32 Debug--------------------
Compiling...
StdAfx.cpp
d:\ydms\stdafx.h(29) : error C2017: illegal escape sequence
d:\ydms\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
Error executing cl.exe.YDMS.exe - 1 error(s), 1 warning(s)
//
//通过在程序中使用预编译指令#import来告诉编译器
//将此指令中指定的动态链接库引入工程中,
//并从动态链接库中取出其中的对象和信息,
//产生msado15.tlh和ado15.tli两个头文件来定义ADO库
//
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")--------------------Configuration: YDMS - Win32 Debug--------------------
Compiling...
StdAfx.cpp
d:\ydms\stdafx.h(29) : error C2017: illegal escape sequence
d:\ydms\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
Error executing cl.exe.YDMS.exe - 1 error(s), 1 warning(s)
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
在就是写在StdAfx.h里的。
rename( "EOF", "adoEOF" ) no_namespace rename("DataTypeEnum", "adoDataTypeEnum")
试试!
#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);
放到Stdafx.h文件中