社区
数据库
帖子详情
Visual C++访问数据库能不能利用预编译SQL?
middle
2002-07-14 06:46:02
在JDBC中有PreparedSentence,用来把SQL语句的语法树保存在服务器端,以便提高类似查询的速度。请问VC访问数据库有没有这样的功能?ODBC,ADO, OLE DB都可以。
...全文
94
5
打赏
收藏
Visual C++访问数据库能不能利用预编译SQL?
在JDBC中有PreparedSentence,用来把SQL语句的语法树保存在服务器端,以便提高类似查询的速度。请问VC访问数据库有没有这样的功能?ODBC,ADO, OLE DB都可以。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
蒋晟
2002-07-18
打赏
举报
回复
ADOX 2.7
See Also
Command Property
© 1998-2001 Microsoft Corporation. All rights reserved.
Command and CommandText Properties Example (VC++)
The following code demonstrates how to use the Command property to update the text of a procedure.
// BeginCommandTextCpp
#import "c:\Program Files\Common Files\system\ado\msadox.dll" \
no_namespace
#import "c:\Program Files\Common Files\system\ado\msado15.dll"
#include "iostream.h"
#include "stdio.h"
#include "conio.h"
//Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void ProcedureTextX(void);
//////////////////////////////////////////////////////////
// //
// Main Function //
// //
//////////////////////////////////////////////////////////
void main()
{
if(FAILED(::CoInitialize(NULL)))
return;
ProcedureTextX();
::CoUninitialize();
}
//////////////////////////////////////////////////////////
// //
// ProcedureTextX Function //
// //
//////////////////////////////////////////////////////////
void ProcedureTextX()
{
HRESULT hr = S_OK;
// Define ADOX object pointers.
// Initialize pointers on define.
// These are in the ADOX:: namespace.
_CatalogPtr m_pCatalog = NULL;
// Define ADODB object pointers.
ADODB::_ConnectionPtr m_pCnn = NULL;
ADODB::_CommandPtr m_pCommand = NULL;
try
{
//Open the Connection
TESTHR(hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection)));
TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));
TESTHR(hr = m_pCommand.CreateInstance(__uuidof(ADODB::Command)));
m_pCnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;"
"data source=c:\\Program Files\\Microsoft Office"
"\\Office\\Samples\\Northwind.mdb;","","",NULL);
//Open the catalog
m_pCatalog->PutActiveConnection(_variant_t((IDispatch *)m_pCnn));
//Get the Command
m_pCommand = m_pCatalog->Procedures->GetItem("CustomerById")->GetCommand();
//Update the CommandText
m_pCommand->PutCommandText("PARAMETERS [CustId] Text;select "
"CustomerId, CompanyName, ContactName "
"from Customers where CustomerId = [CustId]");
//Update the Procedure
m_pCatalog->Procedures->GetItem("CustomerById")->PutCommand(
_variant_t((IDispatch *)m_pCommand));
}
catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\n\tSource : %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
}
catch(...)
{
cout << "Error occured in include files...."<< endl;
}
}
// EndCommandTextCpp
See Also
Command Property
© 1998-2001 Microsoft Corporation. All rights reserved.
middle
2002-07-15
打赏
举报
回复
对不起,还要问一下。我关键是想知道odbc或者ado关于此类操作的api,最好有个例子。如果没有,把api的用法告诉我也可以。
ado的command对象好像使用作此类功能的,不过微软的文档对于带参数(也就是问号)的sql语句解释的不是很清楚,期待解决。
蒋晟
2002-07-15
打赏
举报
回复
也可以啊
用程序生成查询
middle
2002-07-15
打赏
举报
回复
我不是这个意思。我需要像在JDBC里那样,在客户端写好SQL语句,比如
SELECT * FROM TABLE WHERE NAME= ?
然后让数据库在服务器端存储其语法树,以便随后用实际的参数运行查询。
蒋晟
2002-07-14
打赏
举报
回复
都可以……在数据库里面写好查询先
visual
c++
6.0
数据库
编程大全
详细的
数据库
编程,很好的资料,希望可以帮助大家学好V
C++
,谢谢!
Visual
C++
6.0
数据库
开发指南
MFC
数据库
开发专题
visual
c++
6
访问
数据库
绘图制表.rar
visual
c++
6
访问
数据库
绘图制表
visual
c++
6
访问
数据库
绘图制表
visual
c++
6
访问
数据库
绘图制表
visual
c++
6
访问
数据库
绘图制表
Visual
+
C++
与
数据库
管理
Visual
C++
与
数据库
管理,详细介绍
c++
与
数据库
编程!
Visual
c++
数据库
通用模块开发与系统移植
Visual
c++
数据库
通用模块开发与系统移植
数据库
4,018
社区成员
39,807
社区内容
发帖
与我相关
我的任务
数据库
VC/MFC 数据库
复制链接
扫一扫
分享
社区描述
VC/MFC 数据库
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章