|
-
Dec 16th, 2005, 02:27 PM
#1
Thread Starter
Hyperactive Member
[Resolved] Annoying error trying to make functions from Database Connection code..
Here is my "standard code for connecting to an DB, and get something from an Table/Column and then close" divided into three funcions.(big code below)
The thingy is that im gonna use these three seperate functions a lot, and i dont really wanna write all this code in each page im gonna use it in.
I really wanna be able to write this instead of the big code below:
EasyCode:
VB Code:
<!--#include file="FUNCTIONS.ASP"-->
<%
ConnectDB()
DoSomething(ToMyVariable) 'and process an SQL variable here ofcourse
CloseDB()
%>
But right now i get errors like:
ADODB.Recordset (0x800A0BB9)
/FUNCTIONS.ASP, linje 55
So here is my code, and my question, what is wrong???
BIG CODE: (Functions.asp)
VB Code:
<%@ LANGUAGE="VBSCRIPT" %>
<% Function ConnectDB()
Dim Connection 'Here we declare our variable that will hold our new object
Set Connection=Server.CreateObject("ADODB.Connection")
Dim sConnString 'Here we declare our variable that will hold the connection string
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("DB/database.mdb")
Connection.Open sConnString
End Function %>
<% Function DoSomething()
Dim Recordset 'Here we declare our variable that will hold our new object
Set Recordset=Server.CreateObject("ADODB.Recordset")
Dim SQL 'Here we declare our variable that will hold the SQL statement
SQL="SELECT * FROM Produkter"
Recordset.Open SQL, Connection
Do While NOT Recordset.Eof 'i.e. carry on looping through while there are records
Response.write Recordset("Varenavn")
Response.write "<br>" 'include a line break
Recordset.MoveNext 'move on to the next record
Loop
End Function %>
<% Function CloseDB()
Recordset.Close
Set Recordset=Nothing
Connection.Close
Set Connection=Nothing
End Function %>
Last edited by alexdata; Dec 16th, 2005 at 07:59 PM.
Reason: Resolved the issue!!
***************
Please use [highlight=vb] ..your code.. [/highlight] when posting code!
When you have received the working answer to your question,
please mark it as *SOLVED* + Your Questions Title ...using your Thread's Tool menu.
Also try to point out what answer made it work for you, or edit your first post to contain a quote of the correct answer...
Please Answer All Questions With Working Code Examples...
My Unfinished Projects and My working Programs
***************
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|