谁能给我一个例程 ,用ado的oledb访问sql server! 我的email:[email protected] [email protected]收到就给分。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我记得要使用ado,一定要import "C:\..."这个包含的路径可不可以不要用绝对路径,因为系统盘有可能在c:有可能再d:能不能在程序自动找个这个路径啊! 路径问题可以通过GetCurrentDrectory()获得当前目录加以解决. //#import 后面带的路径是编译器用的,相当于.h文件路径一样,你要在源程序中改,可执行文件没有这个路径要求#include "stdafx.h"#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")int main(int argc, char* argv[]){ CoInitialize(NULL); try { _ConnectionPtr pConn("ADODB.Connection"); _RecordsetPtr pRst("ADODB.Recordset"); pConn->Open("Provider=sqloledb;Data Source=Server1;"//Server1:机器名 "Initial Catalog=test1;User Id=sa;Password=sa;",//test1:数据库名 "", "", adConnectUnspecified);// Note 1. pRst->Open( "userinfo",//userinfo:table name _variant_t((IDispatch *) pConn, true), adOpenStatic, adLockReadOnly, adCmdTable); pRst->MoveLast();// Note 2. printf("Last name is '%s %s'\n", (char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()), (char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value)); pRst->Close(); pConn->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); }::CoUninitialize();return 0;} 楼上的不错,不过既然已经用了no_namespace ,怎么还能出现ADO呢?没试过,我瞎说的。 各位,能不能给一段代码,怎样不用绝对路径!#import "C:\....." 怎样变啊? 你可以把msado15.dll拷贝到project目录下,然后用#import "msado15.dll" ... 在vc option 的目录中添上msado15.dll所在的路径。 怎么排除上次已查询过的值 记录分时显示,谢谢 求教一条SQL语句 ----------varchar和nVarchar的烦恼,大家来看看------------ 用dbvisualize的JDBC/ODBC Bridge连接SQlServer2008 sqlserver 2005 不能 导入、导出数据 如何恢复部分数据? 连接SQL SERVER6.5时出错 学哪一种好 中国第一人!我分析出了最新版OICQ消息格式~~! ??各位高手:我想对某一字段进行实时检查,若干小时后对若无更改则...??(在线等待) 为什么这样不行,谁能回答?
这个包含的路径可不可以不要用绝对路径,因为系统盘有可能在c:有可能再d:
能不能在程序自动找个这个路径啊!
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")int main(int argc, char* argv[])
{
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset"); pConn->Open("Provider=sqloledb;Data Source=Server1;"//Server1:机器名
"Initial Catalog=test1;User Id=sa;Password=sa;",//test1:数据库名
"", "", adConnectUnspecified);
// Note 1.
pRst->Open(
"userinfo",//userinfo:table name
_variant_t((IDispatch *) pConn, true),
adOpenStatic,
adLockReadOnly,
adCmdTable);
pRst->MoveLast();
// Note 2.
printf("Last name is '%s %s'\n",
(char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()),
(char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value)); pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
没试过,我瞎说的。
#import "C:\....." 怎样变啊?
#import "msado15.dll" ...