Page 1 of 1 1
Topic Options
#210814 - 2015-10-06 06:45 PM Query SQL for miltiple resultsfoll
Fowzzie Offline
Fresh Scripter

Registered: 2015-10-06
Posts: 6
Loc: UK
I'm trying to create an SQL table to populate a kixforms ComboBox so I'm starting with getting the results from the table firs.

I've got the following script to get the results whitch is working but I also get the following error at the end of the script.

ERROR : Error in expression.!

Script

------------------------------

 Code:
$SQL_Server = "0.0.0.0"
$SQL_Database = "database"
$SQL_User = "sqluserid"
$SQL_Pass = "password"

Break On




$cnstring = "Driver={SQL Server};Server=$SQL_Server;database=$SQL_Database;uid=$SQL_User;pwd=$SQL_Pass" 
																			
$cn = CreateObject("adodb.connection") 
$cmd = CreateObject("adodb.command") 
$rs = CreateObject("adodb.recordset") 
																					
$cn.connectionstring = $cnstring
$cn.Open
																					
$cmd.activeconnection = $cn
$rs.cursortype = 1
$rs.locktype = 3
$rs.activecommand = $cmd
																					
$cmdtext = "Select * from lkp_Departments Order By Department "
			
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

	Do While Not $rs.EOF
		? "Entry: " + $rs.fields.item("Department").value
	
		$rs.MoveNext
	Loop

$rs.Close($cmd)
	
? "done"

------------------------

I know the error is coming from the loop & $rs.movenext but without theses I only get the last result.


Edited by Allen (2015-10-06 09:32 PM)
Edit Reason: added code tags

Top
#210815 - 2015-10-06 09:33 PM Re: Query SQL for miltiple resultsfoll [Re: Fowzzie]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
What line is kix telling you the error is on?
Top
#210816 - 2015-10-07 12:26 AM Re: Query SQL for miltiple resultsfoll [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Rs.close()

Aka, I would try the close the recordset and not send objects to it.
_________________________
!

download KiXnet

Top
#210817 - 2015-10-07 12:28 AM Re: Query SQL for miltiple resultsfoll [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Also, there is no do while in kixtart. Remove the do keyword.
_________________________
!

download KiXnet

Top
#210818 - 2015-10-07 03:09 PM Re: Query SQL for miltiple resultsfoll [Re: Lonkero]
Fowzzie Offline
Fresh Scripter

Registered: 2015-10-06
Posts: 6
Loc: UK
Removing the Do worked. thanks.
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 739 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.055 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org