VBScript-返回数组中的记录集(SQL类函数) [英] VBScript - Return a Recordset in an Array (SQL Like function)

查看:125
本文介绍了VBScript-返回数组中的记录集(SQL类函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为公司的会计师编写程序,并且在归还数组中的商品系列时遇到了问题,我想要的所有系列都需要一个以 707开头的会计代码。这是我在VBScript中的代码:

I have to write a program for my company's accountant, and I have a problem in returning articles' families in an array, all of the families I want to have have an Accounting code who begins with "707". Here's my code in VBScript :

Set objConnection = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\BASES\Base.mdb;Persist Security Info=False"
rs.CursorLocation = adUseClient

FamilleQuery = "Select Code from FamilleArticle Where CptVenteFrance Like '707%'"
rs.Open FamilleQuery, objConnection, adOpenStatic, adLockOptimistic

'rs.MoveFirst
'Do
    'ListeFamille(rs.AbsolutePosition) = rs("Code")
    'rs.MoveNext
'Loop until rs.EOF

'ListeFamilleString = rs.GetString(AdClipString, -1,"/","/"," ")
'ListeFamille = split(ListeFamilleString,"/")

'Set ListeFamille = rs.GetRows

'for i=0 to ubound(rs)
    'ListeFamille(i) = rs.Fields("Code").Value(i)
'next

rs.Close
objConnection.Close

As评论你有我的全部尝试s以数组的形式返回记录集的结果,没有人没有用。
有人可以说我错了吗?

As comments you have all of my attempts to return the resultat of the recordset in an array and no one didn't work. Can someone say where I'm wrong please ?

推荐答案

尝试一下

Option Explicit

'ADO Constants
Const adCmdText = 1
Const adParamInput = 1
Const adVarWChar = 202

'Would usually be passed in from somewhere
Dim value: value = "707%"

Dim cmd, rs, data
Dim conn: conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\BASES\Base.mdb;Persist Security Info=False"
Dim sql: sql = "Select Code from FamilleArticle Where CptVenteFrance Like ?"

Set cmd = Server.CreateObject("ADODB.Command")
With cmd
  .ActiveConnection = conn
  .CommandType = adCmdText
  .CommandText = sql
  Call .Parameters.Append(.CreateParameter("@value", adVarWChar, adParamInput, 50))      

  Set rs = .Execute(, Array(value))
  If Not rs.EOF Then data = rs.GetRows()
  Call rs.Close()
  Set rs = Nothing
End With
Set cmd = Nothing

Dim row, rows

If IsArray(data) Then
  'Test data (2d Array, 0 = column, 1 = row)
  Call WScript.Echo(data(0, 0))

  'Retrieving all rows
  rows = UBound(data, 2)
  For row = 0 To rows
    'First column from each row.
    Call WScript.Echo(data(0, row))
  Next
Else
  'No records returned
End If






有用的链接




  • 在经典ASP中使用存储过程..执行并获取结果 (谈论将数据作为您可以遍历的数组)


  • Useful Links

    • Using Stored Procedure in Classical ASP .. execute and get results (talk about returning data as an Array you can traverse)
    • 这篇关于VBScript-返回数组中的记录集(SQL类函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆