Solved

VBScript Return RecordSet Problem

Posted on 2004-08-22
10
1,101 Views
Last Modified: 2012-08-13
In my VBScript code, I tried to return a result set and put ot into an array, however, error "Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment", a piece of code is as below:


Sub DBConnect()
        Dim sConnect

        On Error Resume Next
        Set g_cnnMBDM = CreateObject("ADODB.Connection")

        sConnect = "Provider=SQLOLEDB"
        sConnect = sConnect & ";Trusted_Connection=yes"
        sConnect = sConnect & ";Server=" & g_sMBDM_SVR
        sConnect = sConnect & ";Database=" & g_sWORK_DB

        g_cnnMBDM.CommandTimeout = g_sMBDM_TIMEOUT
        g_cnnMBDM.Open sConnect

        If Err <> 0 Then WriteError("Error in DBConnect: " & Err.Description) : CleanUp() : Exit Sub
End Sub


Sub GetCurrentDateCubeParameter()

        Dim sSQL, adoRecordSet
      Dim CubeParameter
      Dim i, j
      
      'Get MM Profile cube parameter for current date
      sSQL = "lis_mm_profile_cube_parameter_ct"

      Set adoRecordSet = g_cnnMBDM.Execute(sSQL)
        If adoRecordSet.EOF Then
                g_bError = False
                Call WriteError("No Parameter found for mm_profile_cube generation!"): Exit Sub
        Else
                CubeParameter = adoRecordSet
         i = UBound(CubeParameter,1)
         j = UBound(CubeParameter,2)
        End If

End Sub
0
Comment
Question by:acwng
  • 4
  • 4
  • 2
10 Comments
 
LVL 1

Expert Comment

by:confabber
ID: 11867404
Change ur code like this:

        sConnect = "Provider=SQLOLEDB"
        sConnect = sConnect & ";Trusted_Connection=yes"
        sConnect = sConnect & ";Data Source=" & g_sMBDM_SVR
        sConnect = sConnect & ";Initial Catalog=" & g_sWORK_DB

Replace "Server" with "Data Source"
and "Database" with "Initial Catalog"
0
 
LVL 1

Author Comment

by:acwng
ID: 11867510
The code runs to the line "i = UBound(CubeParameter,1)" then aborted with the same error "Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment"
Any clue?
0
 
LVL 1

Expert Comment

by:confabber
ID: 11867683
UBound Works on Arrays and not on recordsets
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Expert Comment

by:NoshadAhmadi
ID: 11867816
have you defined "g_cnnMBDM" variable as a public variable?

as what we can find in your source code, you creat your database connection in a subrutine and fetch the required data into a recordset in another one using the connection that you have created before, this connection variable should be defined as a public variable to be accessable in both subrutines
0
 
LVL 1

Author Comment

by:acwng
ID: 11867849
confabber,
so how to put the recordset into array format?

NoshadAhmadi,
Yes, it is a global variable.
0
 
LVL 1

Accepted Solution

by:
confabber earned 50 total points
ID: 11867887
This would help u understand better

http://www.aspfaqs.com/ASPScripts/PrintFAQ.asp?FAQID=161
0
 
LVL 1

Author Comment

by:acwng
ID: 11867897
My goal is to return the resultset of the return values of the stored procedure "lis_mm_profile_cube_parameter_ct" into an array format. That's all.
0
 

Expert Comment

by:NoshadAhmadi
ID: 11867898
what did your record set returns? in other word you should know the dimention of the matrix that it would return the fill up the array nodes one by one - instead of working with array I sugget you to work with recordset directly, there are several properties and method available for a record set that facilitates all what you need to do with.
you can get access to each filed using its item no or their related labels, you can navigate the recordset on all records reaching nextrecord, previous, last or the first record and so on..
0
 
LVL 1

Author Comment

by:acwng
ID: 11867980
confabber, you're about right. After I lop thru the result set array, the array is the other way around, i.e. "the rows become the column" and "the column become the rows".
Hoew to make the array inverted?
0
 
LVL 1

Expert Comment

by:confabber
ID: 11868168
Dim iRowLoop, iColLoop
For iRowLoop = 0 to UBound(aTable1Values, 2)
  For iColLoop = 0 to UBound(aTable1Values, 1)
    Response.Write(aTable1Values(iColLoop, iRowLoop) & "<br>")
  Next 'iColLoop

  Response.Write("<p>")
Next 'iRowLoop

Not too sure what u mean by "rows become column and column becomes rows"

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question