Basic ADO and SQL Tutorial
page 3 of 5
by Steven Smith
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 48568/ 214

Command Object

Most ASP texts will jump right into recordsets once you have established your connection. However, if you learn to use the command object right from the start, you'll find that it makes manipulating recordsets much simpler and gives you more options. First, you must create the command object. You do this with the following piece of code:

 'Create Command Object
 Dim objCmd   'Declare the command variable
 Set objCmd = Server.CreateObject("ADODB.Command")
 Set objCmd.ActiveConnection=objConnect
 objCmd.CommandType = adCmdText

Note that you set the command object's ActiveConnection property to your connection object, which you created above. Also note that, in this case, our CommandType is text. This allows us to send SQL commands directly to the database server. If you are using SQL Server as your database, the other command types may prove useful, but for most third party databases, such as Oracle or Informix, you are best off sticking with adCmdText. Also note that adCmdText is a constant. The numeric equivalent is 1. The ADO constants are in a file called adovbs.inc. If you have not already included this file in your current page, locate it(it is installed with ASP - just use the windows Find File command to locate it), copy it to your web directory and rename it adovbsinc.asp. Finally, add this line to the very top of your ASP page:

<!--#INCLUDE VIRTUAL="/yoursubdirectory/adovbsinc.asp"-->

The reason for renaming it is for security purposes -- malicious users can more easily access a file on your server ending in .inc than one ending in .asp.  Although this file is rarely changed and most ASP developers know its contents, it's just good practice not to have any of your code visible to web users.

Now you will be able to use any of the constants found in the rest of this tutorial. Before you can actually use a command object, you need to create a recordset object which references it. So without further ado...

(Update: this isn't entirely true - you can use the Command object without a Recordset to perform database operations that do not return a result set)


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 3 and 1 and type the answer here:

User Comments

Title: nbp   
Name: www
Date: 5/17/2008 3:32:07 PM
Comment:
query of searching data in sqlserver with use of asp.net
Title: swd   
Name: www
Date: 4/29/2008 6:06:09 AM
Comment:
sweet.............
Title: Hi...   
Name: Hann
Date: 3/20/2007 9:49:00 AM
Comment:
Can U tell me how to connect MDB file in other host..?

Plizz, Send your reply to
hann21@linuxmail.org


Thanx
Title: hi   
Name: Paapu
Date: 1/23/2007 1:51:19 AM
Comment:
Its very useful, but still u can add some details also..
Title: hll   
Name: pat
Date: 11/17/2006 5:45:08 AM
Comment:
hello thanks a bunch but i guess i need more help
Title: DotNetSpace   
Name: Simple way to handle exception in database connections
Date: 10/26/2006 1:59:35 PM
Comment:
This is a simple way to handle exceptions when using database queries. This link includes an example:

http://www.dotnetspace.com/index.php?option=com_content&task=view&id=19&Itemid=26
Title: DotNetSpace   
Name: DotNetSpace query database connection example
Date: 10/26/2006 1:58:44 PM
Comment:
Shows a simple way to handle exceptions when using database queries. This link includes the example.
Title: use of loks in asp   
Name: praveen
Date: 7/11/2006 9:56:53 AM
Comment:
Hi

Please provide me the information about locks.
Title: asp stuff   
Name: dhvanil
Date: 4/6/2006 10:12:35 AM
Comment:
hi
your site is good
put some examples of every methods
Title: webmaster   
Name: Yusef Jeffries-El
Date: 1/15/2006 1:10:43 AM
Comment:
I just needed a quick reference to the syntax of the INSERT INTO statement using Visual Basic
Title: hi   
Name: vishal
Date: 6/3/2005 10:17:27 AM
Comment:
vishal patel your site is so genious but add the download button on every page






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 12/2/2008 9:50:40 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search