Forum Moderators: open

Message Too Old, No Replies

Problems with database class and Reading files

database class

         

siu04tsl

11:39 pm on Mar 11, 2006 (gmt 0)



Hi I've made a function to communicate with my database. Basically it saves me time from writing out another 6 lines of codes when making a connection to the database, this is in my config.asp:

Function executeRead(sql)
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open dbStr
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sql, oConn, 3, 4
Set rs.ActiveConnection = Nothing
executeRead = rs
oConn.Close
Set oConn = Nothing
Set rs = Nothing
End Function

and in my nav.asp i try and call that function:

rs = executeRead("SELECT * FROM ioms_nav")
While (NOT rs.EOF)
response.write rs("n_name")
rs.MoveNext()
Wend
rs.close

i was hoping to create a connection using executeRead and return the result to use it in nav.asp but it doesn't seem to like it.

Also my index.asp can read in an asp file and store it into a variable called "output". However when i do Response.Write(output) it just writes the page out as html format. Is there a way i can just read the asp file and use the code within that file?

Please help me.

Thank You

aspdaddy

10:52 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your function fails because you are closing the connection, IMO you are better off writing functions just to open and close the connections:

openDatabase( objConn )
set rs = objConn.Execute("SELECT * FROM ioms_nav")
' do stuff
closeDatabase( objConn )

Or use a disconnected recordsets instead.
Google for "Display Recordset Data in a Paged Fashion" for a good aexample of this.

For the the second question, you can use server.Execute or Response.Redirect to execute code in another page.