ASP连接存储过程并读取数据

ASP   2025-01-17 20:47   66   0  
<%
'SQLServer2008存储过程执行代码
'USE [bds257174220_db]
'GO
'DECLARE	@return_value int
'EXEC	@return_value = [dbo].[newsstorage]
'SELECT	'Return Value' = @return_value
'return
'GO

' 创建连接字符串
Const strConnectionString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=database;User ID=sa;Password=123456;"
' 创建ADODB.Connection对象
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
' 打开连接
objConn.Open strConnectionString
' 创建ADODB.Command对象
Dim objCmd
Set objCmd = Server.CreateObject("ADODB.Command")
' 设置Command对象的属性
With objCmd
    .ActiveConnection = objConn    ' 关联到连接对象
    '.CommandType = adCmdStoredProc ' 指定命令类型为存储过程
	.CommandType = 4 ' 指定命令类型为存储过程
    .CommandText = "newsstorage" ' 设置存储过程名称
    ' 添加参数(如果有)
    '.Parameters.Append .CreateParameter("参数名", adVarChar, adParamInput, 50, "参数值")
	.Prepared = true '要求将SQL命令先预编译
End With

' 执行存储过程
Dim rs
Set rs = objCmd.Execute
'将执行的存储过程结果读取出来
if not rs.eof then
	Do While Not rs.EOF
		response.Write(rs("AddDate"))
		rs.MoveNext
	Loop
	'response.redirect "https://www.sohu.com/"
else
	response.redirect "https://www.baidu.com/"
end if
	
' 清理对象
objCmd.ActiveConnection = Nothing
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing
%>


博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。