Functions and DB

Results 1 to 2 of 2

Thread: Functions and DB

  1. #1
    Luís Fernando Guest

    Default Functions and DB

    Hi, <BR><BR>I have a file with 10 functions to manipulate a database. All the functions need to open and close the Database. So, I created functions called open_db and close_db. <BR><BR>I named the recordset as rsDC. But when I try to use rsDC("somefield") it gives an error saying that rsDC is needed (or doesn&#039t exist). It happens the same when I try to use the close_db. <BR><BR>Look at my open and close functions.. I think there are no errors, because when I paste the code in all the other functions.. it works<BR><BR><BR>function open_db()<BR>Set DataConn = Server.CreateObject("ADODB.Connection")<BR>DataCon n.Open "loja"<BR>Set cmdDC = Server.CreateObject("ADODB.Command")<BR>cmdDC.Acti veConnection = DataConn<BR>cmdDC.CommandText = "SELECT * FROM store"<BR>cmdDC.CommandType = 1<BR>Set rsDC = Server.CreateObject("ADODB.Recordset")<BR>rsDC.Ope n cmdDC<BR>end function<BR><BR>function close_db()<BR>DataConn.Close<BR>Set DataConn = nothing<BR>Set cmdDC = nothing<BR>Set rsDC = nothing<BR>end function<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Functions and DB

    Add this line at the end of function open_db() and see if you have any luck.<BR><BR>open_db=rsDC<BR><BR>Then in your other funcions do this:<BR><BR>rsLocal=open_db()<BR><BR>See if that helps out at all.<BR><BR>Kurt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts