Database
  Home arrow Database arrow Page 2 - Portable Database Functions
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Portable Database Functions
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 40
    2003-12-29

    Table of Contents:
  • Portable Database Functions
  • Tool #1: Quick Execution
  • Tool #2: How Fast Can You Count?
  • Tool#3: I'll Use My Own ID, Thank You
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Portable Database Functions - Tool #1: Quick Execution


    (Page 2 of 5 )

     

    Already you’re thinking that it is very simple to execute a SQL statement. It’s really only 6 lines of code, providing you have a connection string and SQL statement:

     

    dim objConn

    set objConn = Server.CreateObject("ADODB.Connection")

    objConn.Open( your connection string )

    objConn.Execute( SQL statement )

    objConn.Close()

    set objConn = Nothing

     

    Could it really be any simpler? Well, of course, or else I wouldn’t be writing this article! When you think about it, each time you need to write 6 more lines of code. This little block of code also gives you approximately 150 more opportunities to mistype a character, resulting in time lost due to debugging. And trust me, by the 50th time you write objConn.Close() in your application, you will inexplicably begin to despise each o, b, j, etc. that you have to type to perform the same simple procedure as the other 49 times.

     

    So, here’s the tool to turn those 6 lines of monotony into 1 line of excitement. Well, maybe you won’t be that excited by it, but nonetheless, here it is:

     

    '================================

    Sub commitToDB( strSQL2, strDB )

    '================================

     

           If strSQL2 = "" Then Call errorMessage( "Cannot commit empty string!" )

                 

           If strDB = "" Then strDB = Application("MySQL_inventory")

           ‘=== in case you call several DBs from your application

    ‘===Application("MySQL_inventory") is the default

     

           Dim objConn

           Set objConn = Server.CreateObject("ADODB.Connection")

          

    objConn.Open( strDB )

           objConn.Execute( strSQL2 )

           objConn.Close()

     

           Set objConn = Nothing

          

    End Sub

     

     

    Explanation

     

    This subprocedure takes a SQL statement, and executes it on the default connection unless another is specified. The call errorMessage() is explained in the article “Easy Error Management”, basically just a way to explain in plain English that there’s a problem. Other than that, nothing miraculous is accomplished here, except for the fact that now when you wish to execute a statement, it only requires that you type the following:

     

    Call commitToDB( strSQL, “” )

     

    Wasn’t that easy? Honestly, it brings me a strange sense of satisfaction to type in this one line of code and move on with my life!

    More Database Articles
    More By Justin Cook


     

    DATABASE ARTICLES

    - Converting Your Excel Worksheet into a Worki...
    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT