从经典ASP中的函数返回记录集
发布时间:2020-05-23 21:07:36 所属栏目:asp.Net 来源:互联网
导读:我对如何从经典ASP中的函数返回可读记录集感到茫然. 这就是我提出的,但它不起作用: Response.ClearResponse.CharSet = utf-8Response.ContentType = text/plainDim CountSet Count = TestResponse.Write Count.Fields(0).ValueFunction T
|
我对如何从经典ASP中的函数返回可读记录集感到茫然. 这就是我提出的,但它不起作用: Response.Clear
Response.CharSet = "utf-8"
Response.ContentType = "text/plain"
Dim Count
Set Count = Test
Response.Write Count.Fields(0).Value
Function Test
Dim Query,Connection,Command,Recordset
Query = " blah blah blah "
Set Connection = Server.CreateObject("ADODB.Connection")
Set Command = Server.CreateObject("ADODB.Command")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.ConnectionString = "blah blah blah"
Connection.Open
Set Command.ActiveConnection = Connection
Command.CommandText = Query
Set Recordset = Command.Execute
Set Test = Recordset
Recordset.Close
Connection.Close
Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing
End Function
Response.Write Count.Fields(0).Value行产生无法在与请求的名称或序号对应的集合中找到Item.错误. 用Response.Write Count.Status替换它我在对象关闭时不允许操作.错误. 添加Count.Open会给出连接不能用于执行此操作.在此上下文中它是关闭的或无效的.错误. 马克B回答后编辑: 我已经查看了断开连接的记录集,但我不知道如何在我的示例中使用它们:每个教程都使用Recordset.Open直接将查询提供给记录集,但我使用的是参数化查询,甚至尝试了很多方法我无法当路上有ADODB.Command时,获得相同的结果. 我该怎么办? 提前致谢. 以下是基于Eduardo Molteni答案的解决方案: 与数据库交互的函数: Function Test
Dim Connection,Recordset
Set Connection = Server.CreateObject("ADODB.Connection")
Set Command = Server.CreateObject("ADODB.Command")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.ConnectionString = "blah blah blah"
Connection.Open
Command.ActiveConnection = Connection
Command.CommandText = "blah blah blah"
Recordset.CursorLocation = adUseClient
Recordset.Open Command,adOpenForwardOnly,adLockReadOnly
Set Recordset.ActiveConnection = Nothing
Set Test = Recordset
Connection.Close
Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing
End Function
调用函数的代码: Response.Clear Response.CharSet = "utf-8" Response.ContentType = "text/plain" Dim Recordset Set Recordset = Test Response.Write Recordset.Fields(0).Value Recordset.Close Set Recordset = Nothing 解决方法这是一个返回断开连接的记录集的函数Function RunSQLReturnRS(sqlstmt,params())
On Error Resume next
''//Create the ADO objects
Dim rs,cmd
Set rs = server.createobject("ADODB.Recordset")
Set cmd = server.createobject("ADODB.Command")
''//Init the ADO objects & the stored proc parameters
cmd.ActiveConnection = GetConnectionString()
cmd.CommandText = sqlstmt
cmd.CommandType = adCmdText
cmd.CommandTimeout = 900
''// propietary function that put params in the cmd
collectParams cmd,params
''//Execute the query for readonly
rs.CursorLocation = adUseClient
rs.Open cmd,adLockReadOnly
If err.number > 0 then
BuildErrorMessage()
exit function
end if
''// Disconnect the recordset
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
Set rs.ActiveConnection = Nothing
''// Return the resultant recordset
Set RunSQLReturnRS = rs
End Function (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – IIS Express – HTTP错误500.19 0x800700b7
- asp.net-mvc – 不引人注意的MVC3验证组的复选框
- asp.net – 选择框更改事件中的setTimeout
- 三重报价?如何在ASP.NET中分隔数据绑定的JavaScript字符串
- asp.net-mvc – LabelFor和TextBoxFor不生成相同的id
- asp.net-mvc – 如何将ASP.Net MVC路径段中的1或0映射到布尔
- ASP.NET API版本控制
- asp.net-mvc – 异步操作方法
- asp.net-mvc – 更改ASP.NET MVC 3中的默认ModelState错误消
- asp.net-core – 在Microsoft.AspNet.Http.HttpContext中的
推荐文章
站长推荐
- asp.net – 在成功登录时添加声明并在应用程序的
- asp.net – 错误:类型存在于两个目录中
- ASP.NET代码隐藏中的当前工作目录 – 我们可以依
- asp.net-mvc – Asp.net Identity:User.Identit
- 决定Umbraco和Orchard之间ASP.NET CMS
- asp.net-mvc – ASP.NET MVC – 主页面和视图页面
- asp.net – System.Web.HttpException:请求超时
- asp.net-mvc – Visual studio – 预编译 – 无点
- asp.net * WebForms *开发人员将来可以期待什么?
- asp.net-mvc – Angular ng-include cshtml页面
热点阅读
