Sign in to follow this  
Followers 0
kiffab

SQL output more than 1 row

3 posts in this topic

Hi

I have a query which should return multiple rows from a database. I want to write these to file. However, my code only seems to output a single row.

How would i go about writing all the rows the query returns?

Thanks

; Specify an ini file to write to
$sIni = @ScriptDir &  "\Documents.ini"

; Connect to the database
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=server1;DATABASE=database1;UID=test1;PWD=test1;"
$conn.Open($DSN)

;Create record set and run query
$rs = ObjCreate("ADODB.RecordSet")
$rs.Open("select filename+'.pdf' 'file' from test where id > 0", $conn)

; Write results to file
Iniwrite($sIni, "Documents", "file", $rs.Fields("file").value)

$conn.close

Thanks in advance for any help :huh2:

Share this post


Link to post
Share on other sites



Searching this forum should give you answer too

; Specify an ini file to write to
$sIni = @ScriptDir &  "\Documents.ini"

; Connect to the database
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=server1;DATABASE=database1;UID=test1;PWD=test1;"
$conn.Open($DSN)

;Create record set and run query
$rs = ObjCreate("ADODB.RecordSet")
$rs.Open("select filename+'.pdf' 'file' from test where id > 0", $conn)

If $RS.RecordCount Then
    While Not $RS.EOF
        Consolewrite("file: " & $rs.Fields("file").value & @CRLF)
        $RS.MoveNext
    WEnd
EndIf
    
$RS.Close
$conn.close

Share this post


Link to post
Share on other sites

Exactly what i needed. Thank you :huh2:

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