Access Database Library

This is a discussion on "Access Database Library" within the Classic ASP section. This forum, and the thread "Access Database Library are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 15th, 2003, 23:58
vor vor is offline
Junior Member
Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Access Database Library

Here is the function library that I used to use in Asp. I'm an ASP.NET person now. Hopefully some of you will enjoy it. It has basic stuff, Grab single String, Return Array, Open a Disconnected Recordset and regular recordets.

This should really be made into a Class, but eh. Enjoy.

Code: Select all
'Library Written by Pedro "VoR" Sousa
Dim conn, rec 'Global Connection Object Vars

'xtype: 0 = create rec & conn and disconnect , 1 = create rec then Disconnect
function DBdiscRec(sqlcode,xtype,dbFilePath)'Create a Closed RecordSet.
  if xtype = 0 then
     set conn = Server.CreateObject("ADODB.Connection")
     conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =  " + dbFilePath  +";"    
     conn.open
  end if
  
  set rec = Server.CreateObject("ADODB.RecordSet")
  With(rec)
     .CursorLocation = 3
     .LockType = 1
     .Open sqlcode, conn,,,0
     Set .ActiveConnection = Nothing 
  end with
  
  if xtype = 0 then DBclose "conn" 'Now Close the Connection
end function

'==============================================================================================
function DBcloseConnOnRec()'Disconnects RecordSet and Closes Conn
   set rec.ActiveConnection = Nothing 
   conn.close: set conn = nothing 'Now Close the Connection
end function

'==============================================================================================
'xtype : 0 = Connection , 1 = w/ RecordSet for Read, 2 = w/ Recordset for Write
function DBconnection(sqlcode,xtype,dbFilePath)
  set conn = Server.CreateObject("ADODB.Connection")
  conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =  " + dbFilePath  +";"
  conn.open
  
  select case xtype 
     case 1 'Read
         set rec = Server.CreateObject("ADODB.RecordSet")
         rec.open sqlcode,conn,3,1,0 
     case 2 'Write
          set rec = Server.CreateObject("ADODB.RecordSet")
          rec.open sqlcode,conn,3,3,0
   end select
end function

'==============================================================================================
'xtype : 0 = create Connection, 1 = Use Global Connection
function DBreturnArray(sqlcode,xtype,dbFilePath)
   dim trec,tconn
     set trec = Server.CreateObject("ADODB.RecordSet")
   
   'Setup RecordSet, Must use Disconnected Record Set to prevent memo Cropping when Counting on Joined Table
   if xtype = 0 then 'Create Connection
      set tconn = Server.CreateObject("ADODB.Connection")
      tconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =  " + dbFilePath  +";"    
      
      trec.CursorLocation = 3 : trec.LockType = 1
      tconn.open : trec.Open sqlcode, tconn,,,0
      
      Set trec.ActiveConnection = Nothing 
      tconn.close : set tconn = nothing
      
   else 'Use Global Connection ============
      set trec = Conn.Execute(sqlcode)
   end if

    if not trec.eof then
       DBreturnArray = trec.getrows()
    else
       DBreturnArray = ""
    end if
    trec.close : set trec = nothing
end function

'==============================================================================================
function DBreturnVar(sqlcode,varName)
   dim trec
   set trec = Conn.Execute(sqlcode)
   if not trec.eof then
      DBreturnVar = trec(varName)
   else
      DBreturnVar  = ""
   end if
   trec.close : set trec = nothing
end function

'==============================================================================================
function DBexecute(sqlcode,dbFilePath)
  dim tconn
  set tconn = Server.CreateObject("ADODB.Connection")
  tconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =  " + dbFilePath  +";"    
  tconn.open : tconn.execute(sqlcode)
  tconn.close : set tconn = nothing
end function

'==============================================================================================
function DBclose(xtype)
  select case xtype
     case "rec"
         rec.close: set rec = nothing
     case "conn"
         conn.close: set conn = nothing
     case "all"
         rec.close: set rec = nothing
         conn.close: set conn = nothing
  end select
end function

  #2 (permalink)  
Old Aug 16th, 2003, 08:16
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Nice functions...

I have a set very similar but are heaviliy modified for my own site content management system which runs my own site:- www.dotmagic.co.uk

Excellent contribution...

Thanx
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Closed Thread

Tags
access, database, library

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
using access database ? saadi babar Classic ASP 13 Mar 19th, 2008 09:45
Connection to access database thriftyspider Other Programming Languages 1 Aug 7th, 2007 20:41
Searchable Library Database - How?? SkyeGospel Starting Out 9 Aug 7th, 2007 08:20
Access Database benjamjon Databases 1 Mar 8th, 2007 20:19
Access database on the Web redkyna Databases 7 Aug 2nd, 2004 20:25


All times are GMT. The time now is 06:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43