Sign in to follow this  
Followers 0
supahfly

Help with SQL array

9 posts in this topic

Hi guys,

can any one help me to explain why my message box doesnt show the array data?

im not a programmer but its working so far!

CODE
#include <_sql.au3>

#include <array.au3>

_SQLRegisterErrorHandler();register the error handler to prevent hard crash on COM error

$con = _SQLStartup()

If @error then Msgbox(0,"Error","Error starting ADODB.Connection")

_sqlConnect(-1,"192.168.145.37\MSSQL05","Softricity","sa","Welkom01")

$aData = _SQLExecute(-1,"SELECT * FROM dbo.CODES")

$Data = _SQLGetData2D($aData) ; make an array

;_arrayDisplay($Data,"export") ;show array

$c = UBound ( $Data)

MsgBox(1024,"query",$c) ; gives value 93

for $i = 1 to $c

MsgBox(1024,"Hello", $Data[$i]) ; <<<===== doesnt show the array data one for one.

next

_SQLClose()

hope someone helps me with a solution.

Best Regards,

Marcel

Share this post


Link to post
Share on other sites



Hi guys,

can any one help me to explain why my message box doesnt show the array data?

im not a programmer but its working so far!

CODE
#include <_sql.au3>

#include <array.au3>

_SQLRegisterErrorHandler();register the error handler to prevent hard crash on COM error

$con = _SQLStartup()

If @error then Msgbox(0,"Error","Error starting ADODB.Connection")

_sqlConnect(-1,"192.168.1.2\MSSQL05","Software","sa","abcdef01")

$aData = _SQLExecute(-1,"SELECT * FROM dbo.CODES")

$Data = _SQLGetData2D($aData) ; make an array

;_arrayDisplay($Data,"export") ;show array

$c = UBound ( $Data)

MsgBox(1024,"query",$c) ; gives value 93

for $i = 1 to $c

MsgBox(1024,"Hello", $Data[$i]) ; <<<===== doesnt show the array data one for one.

next

_SQLClose()

hope someone helps me with a solution.

Best Regards,

Marcel

If it's a 2D array then you are missing an index, i.e. $Data[$i][0].

Ubound() returns a count, but AutoIt uses 0-based indexes. So you want to loop "0 To $c - 1" or "1 To $c - 1".

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If it's a 2D array then you are missing an index, i.e. $Data[$i][0].

Ubound() returns a count, but AutoIt uses 0-based indexes. So you want to loop "0 To $c - 1" or "1 To $c - 1".

:)

yeah your right!

this works

CODE
$c = UBound ( $Data)

MsgBox(1024,"query",$c) ; gives value 93

for $i = 0 To $c - 1

MsgBox(1024,"Hello", $Data[$i][0])

next

but only shows col 0 now,

is it possible to show all collums in that array line?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

yeah your right!

this works

CODE
$c = UBound ( $Data)

MsgBox(1024,"query",$c) ; gives value 93

for $i = 0 To $c - 1

MsgBox(1024,"Hello", $Data[$i][0])

next

but only shows col 0 now,

is it possible to show all collums in that array line?

Not with a single reference. You would have to assemble the string something like this:
MsgBox(1024, "rows", UBound($Data)); gives value 93

For $r = 0 To UBound($Data) - 1
    $sTemp = "Row " & $r & " = "
    For $c = 0 To UBound($Data, 2)
        ; $r = row, $c = column
        $sTemp &= $Data[$r][$c] & "|" 
    Next
    $sTemp = StringTrimRight($sTemp, 1)
    MsgBox(1024, "Row " & $r, $sTemp)
Next

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Not with a single reference. You would have to assemble the string something like this:

MsgBox(1024, "rows", UBound($Data)); gives value 93

For $r = 0 To UBound($Data) - 1
    $sTemp = "Row " & $r & " = "
    For $c = 0 To UBound($Data, 2)
    ; $r = row, $c = column
        $sTemp &= $Data[$r][$c] & "|" 
    Next
    $sTemp = StringTrimRight($sTemp, 1)
    MsgBox(1024, "Row " & $r, $sTemp)
Next

:)

omg... now you lost me....

thanks for the big help but this is too complicated to understand..... :lmao:

Share this post


Link to post
Share on other sites

omg... now you lost me....

thanks for the big help but this is too complicated to understand..... :lmao:

Don't be ridiculous. You were already using a 2D array, and Ubound(). Is a For\Next loop really that complicated?

Take it one line at a time, as this stuff is worth learning, and ask about the lines you don't understand.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hmm still need this technique.

Anyone some more tips for me?

Share this post


Link to post
Share on other sites

PsaltyDS has given you everything you need. What else do you need?

Share this post


Link to post
Share on other sites

Anyone some more tips for me?

Your question implies you have done nothing since January (Almost ten months ago!) to learn anything about this. There is zero chance of you understanding this without putting any effort into it.

Do the simple tutorials in the help file. Then do the AutoIt 1-2-3 tutorial linked in my sig. Go back over the simple For/Next loop I posted earlier and come up with a specific question about what you don't understand.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0