Solved

VBScript Return RecordSet Problem

Posted on 2004-08-22
10
1,097 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is the compatible hibernate version for spring 4.3.1 10 60
wefewf 2 43
bunnyEars challenge 6 62
VB 6.0 printer how to align 6 49
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now