[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
Re: Annoying error when trying to make functions from standard Database Connection code..
Number one rule: NEVER use reserved keywords or class names for your variable names. Change your connection and Recordset variables to a different name and try it again.
Well.. after lots of hustle, i managed to make the CONNECT, DISCONNECT and the ASK the DB into three files.. and the Three files is called from the fourth.. in this EX: index.asp
So now i can call these "functions" (files) from any file whom needs it..
Well.. now, i'll try to put this into ONE file, an FUNCTIONS.ASP
but for now, i'll upload this, so others can look at it, and hopefully use it..
*************** 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...
well.. afterall.. after coding the previous example where each function had a file...
I easily now managed to create an FUNCTIONS.ASP
So now you can call functions like CONNECt and DISCONNECT from the FUNCTIONS.ASP file.. a real relief.. when it comes to not having to rewrite code each time you have to use it in another AP file..
Hehe, so now i put ConneciIT() instead og that long procedure we normally do.. just remember to INCLUDE the functions.asp in all files whre you need those functions..
I upload the finished result here, for everyone to enjoy!!!
*************** 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...