Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - GetRows question...

Reply
 
Old 11-13-2008   #1 (permalink)
Ken D.


 
 

GetRows question...

I am attempting to extract a column of data from SQL and store it into an
array. When I attempt to display the array's contents, I don't see the
results. Here is my code:

'Create the Recordset
strSQL = "SELECT month FROM graph_LM_time_all "

'Open the Recordset
objRS.Open strSQL, objConn

'Create the Array
Dim myArray
myArray = objRS.GetRows()

'Loop through the Array and write the results
Dim i
For i=0 to UBound(myArray)
Response.Write myArray(i,0) & "<br />"
Next

I get no results returned. What am I missing?




My System SpecsSystem Spec
Old 11-13-2008   #2 (permalink)
gimme_this_gimme_that


 
 

Re: GetRows question...


You have to loop though the elements of the result set to get the
data.
My System SpecsSystem Spec
Old 11-13-2008   #3 (permalink)
Al Dunbar


 
 

Re: GetRows question...


"Ken D." <KenD@xxxxxx> wrote in message
news:5BC23987-1C83-4E94-ACA4-0470262F7B38@xxxxxx
Quote:

>I am attempting to extract a column of data from SQL and store it into an
> array. When I attempt to display the array's contents, I don't see the
> results. Here is my code:
>
> 'Create the Recordset
> strSQL = "SELECT month FROM graph_LM_time_all "
>
> 'Open the Recordset
> objRS.Open strSQL, objConn
>
> 'Create the Array
> Dim myArray
> myArray = objRS.GetRows()
add this and tell us what it displays:

response.write "[" & ubound(myArray) & "]"
Quote:

> 'Loop through the Array and write the results
> Dim i
> For i=0 to UBound(myArray)
> Response.Write myArray(i,0) & "<br />"
> Next
>
> I get no results returned. What am I missing?
Also, is myArray a one-dimensional array, or a two-dimensional one?

/Al


My System SpecsSystem Spec
Old 11-14-2008   #4 (permalink)
ekkehard.horner


 
 

Re: GetRows question...

Ken D. schrieb:
Quote:

> I am attempting to extract a column of data from SQL and store it into an
> array. When I attempt to display the array's contents, I don't see the
> results. Here is my code:
>
> 'Create the Recordset
> strSQL = "SELECT month FROM graph_LM_time_all "
>
> 'Open the Recordset
> objRS.Open strSQL, objConn
>
> 'Create the Array
> Dim myArray
> myArray = objRS.GetRows()
>
> 'Loop through the Array and write the results
> Dim i
> For i=0 to UBound(myArray)
> Response.Write myArray(i,0) & "<br />"
> Next
>
> I get no results returned. What am I missing?
..GetRows returns a two dimensional array: first dimension cols,
second dimension rows. See:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sTDir : sTDir = oFS.GetAbsolutePathName( ".\adotext" )
Dim sTable : sTable = "jmastrianb"
Dim sCS : sCS = Join( Array( _
"Provider=MSDASQL.1" _
, "Driver={Microsoft Text Driver (*.txt; *.csv)}" _
, "DBQ=" & sTDir _
), ";" )
Dim oCN : Set oCN = CreateObject( "ADODB.Connection" )
oCN.Open sCS
Dim sSQL : sSQL = "SELECT * FROM [" & sTable & ".txt]"
Dim oRS : Set oRS = oCN.Execute( sSQL )

Dim aData : aData = oRS.GetRows()
WScript.Echo "cols:", UBound( aData, 1 ) + 1
WScript.Echo "rows:", UBound( aData, 2 ) + 1
Dim nRow
For nRow = 0 To UBound( aData, 2 )
Dim nCol
For nCol = 0 To UBound( aData, 1 )
WScript.Echo nRow, nCol, aData( nCol, nRow )
Next
WScript.Echo
Next

oRS.Close
oCN.Close

output:

=== demoGetRows: demo .GetRows() =======
cols: 3
rows: 4
0 0 123
0 1 7654321
0 2 123456789

1 0 12
1 1 Joe
1 2 Bellmonts

2 0 1
2 1 A
2 2 Short

3 0 33
3 1 Deborah
3 2 Whereever

=== demoGetRows: 0 done (00:00:01) =====
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
escape character question - hopefully an easy question PowerShell
question is Vista mail
Question Vista mail
vista genral question and ultimate question Vista General
Dual boot system question and family deal discount question Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46