C#(CSharp) | VC/C++ | ASP(ASP.NET) | SQL Server | OpenGL | CMM | 网站开发SEO | 数控技术 | 地理信息系统 | WINDOWS操作系统 |
联高软件 > 技术文档 > VC_VC++_VC.NET > 用数据库存取数据 VC_VC++_VC.NET软件开发参考文档

用数据库存取数据

发表:联高软件www.legalsoft.com.cn,本文被阅读:3592

摘要:文章:用数据库存取数据 摘要:作者:飞刀 概述这篇文章用了三种方法来存取步骤。这一切都是都是通过在ActiveServerPage中调用Active,发表于北京联高软件有限公司技术文章栏目,代码以高亮显示。
关键字:数据, 存取, 数据库, br, cmd, the, parameters, set, cn, server, stored, procedure, method, of, createobject, adodb, calling

作者: 飞刀
概述 这篇文章用了三种方法来存取步骤。这一切都是都是通过在Active Server Page中调用ActiveX Date Objects(ADO)来实现的! 更多的信息 下面的例子使用Command对象来实现。这个例子,存一个数字,最后也取出一个数字!
<%@ LANGUAGE="VBSCRIPT" %>


Place Document Title Here

This first method queries the data source about the parameters
of the stored procedure. This is the least efficient method of calling
a stored procedure.

<%
Set cn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
cn.Open "data source name", "userid", "password"
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_test"
cmd.CommandType = adCmdStoredProc
" Ask the server about the parameters for the stored proc
cmd.Parameters.Refresh
" Assign a value to the 2nd parameter.
" Index of 0 represents first parameter.
cmd.Parameters(1) = 11
cmd.Execute
%>
Calling via method 1

ReturnValue = <% Response.Write cmd.Parameters(0) %>



Method 2 declares the stored procedure, and then explicitly declares
the parameters.

<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "data source name", "userid", "password"
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn
cmd.CommandText = "sp_test"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _
adParamReturnValue)
cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
adParamInput)
" Set value of Param1 of the default collection to 22
cmd("Param1") = 22
cmd.Execute
%>
Calling via method 2

ReturnValue = <% Response.Write cmd(0) %>



Method 3 is probably the most formal way of calling a stored procedure.
It uses the canocial
<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "data source name", "userid", "password"
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn
" Define the stored procedure"s inputs and outputs
" Question marks act as placeholders for each parameter for the
" stored procedure
cmd.CommandText = "{?=call sp_test(?)}"
" specify parameter info 1 by 1 in the order of the question marks
" specified when we defined the stored procedure
cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _
adParamReturnValue)
cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
adParamInput)
cmd.Parameters("Param1") = 33
cmd.Execute
%>
Calling via method 3

ReturnValue = <% Response.Write cmd("RetVal") %>




注意在上面的例子中,许多的Parameters属性被调用。有的是使用默认值,有些则是使用指定的值。
[VC_VC++_VC.NET] Visual C++实现数字图像增强处理 (5175)
[VC_VC++_VC.NET] 基于Visual C++的Winsock API研究 (3160)
[VC_VC++_VC.NET] VC无模式对话框 (6473)
[VC_VC++_VC.NET] 在VS.NET下创建文件上载控件 (3057)
[VC_VC++_VC.NET] 在Visual C++中使用内联汇编 (3745)
[VC_VC++_VC.NET] window中进程间如何通信 (3461)


www.315soft.com