PDA

View Full Version : correct use of a function?



numbenator
18 Aug 2005, 03:24 AM
Hi There,
Im doing a lot of access to a db and retrieval of all informaiton in numerous tables. Now i know that should be using stored procedures bu i am trying to get my head into functions and thus have the below question.

Ive created a function shown below called getALL. I want it to return a recordset so as I can then process the information retrieved.
In my sub, how do i use this function and continue processing after the retrieval of the recordset. I start erroring when i attempt to code use and though sumone could look over.

cheers

my function which is defined in a SSI
Conn (the connection) is defined in another SSI.


function getAll(tableName)

Set RS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM "&dbName
RS.Open strSQL, Conn
getAll=RS

end function



sub getSelectTable(tableName)

tabN=tableName
function call here i assume
RS.MoveFirst

'process recordset here

sajjad27s
24 Sep 2005, 09:51 AM
Hello .........

Your getAll(..) function is OK but callit like this, I am sure it will not raise any error

sub getSelectTable(tableName)

tabN=tableName
Set RS = Server.CreateObject("ADODB.Recordset")
Set RS = getAll(tabN)
RS.MoveFirst

'process recordset here



If it shows error then try after comment then following line

Set RS = Server.CreateObject("ADODB.Recordset")