Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADO and VBScript

Posted on 2001-09-10
7
Medium Priority
?
993 Views
Last Modified: 2012-05-04
How do I use ADO with VBScript?
0
Comment
Question by:rtcomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6471385
from ADOdb.com:
ADO in VBScript
Creating an ADO Project
VBScript does not support type libraries, so you do not need to reference ADO in your project. Consequently, no associated features such as command line completion are supported. Also, by default, ADO enumerated constants are not defined in VBScript.

However, ADO provides you with two include files containing the following definitions to be used with VBScript:

For server-side scripting use Adovbs.inc, which is installed in the c:\Program Files\Common Files\System\ado\ folder by default.


For client-side scripting use Adcvbs.inc, which is installed in the c:\Program Files\Common Files\System\msdac\ folder by default.
You can either copy and paste constant definitions from these files into your ASP pages, or, if you are doing server-side scripting, copy Adovbs.inc file to a folder on your Web site and referencing it from your ASP page like this:

<!--#include File="adovbs.inc"-->

Creating ADO Objects in VBScript
You cannot use the Dim statement to assign objects to a specific type in VBScript. Also, VBScript does not support the New syntax used with the Dim statement in Visual Basic for Applications. You must instead use the CreateObject function call:

Dim Rs1
Set Rs1 = Server.CreateObject( "ADODB.Recordset" )

VBScript Examples
The following code is a generic example of VBScript server-side programming in an Active Server Page (ASP) file:

<%  @LANGUAGE="VBSCRIPT" %>
<%  Option Explicit %>
<!--#include File="adovbs.inc"-->
<HTML>
    <BODY BGCOLOR="White" topmargin="10" leftmargin="10">

    <!-- Your ASP Code goes here -->
<%
Dim Source
Dim Connect
Dim Rs1
   
Source = "SELECT * FROM Authors"
Connect = "Provider=sqloledb;Data Source=srv;" & _
    "Initial Catalog=Pubs;User Id=sa;Password=;"

Set Rs1 = Server.CreateObject( "ADODB.Recordset" )
Rs1.Open Source, Connect, adOpenForwardOnly
Response.Write("Success!")
%>
    </BODY>
</HTML>

More specific VBScript examples are included with the ADO documentation. For more information, see ADO Code Examples in Microsoft Visual Basic Scripting Edition.

Differences Between VBScript and Visual Basic
Using ADO with VBScript is similar to using ADO with Visual Basic in many ways, including how syntax is used. However, some significant differences exist:

VBScript supports only the Variant data type, which can hold different types of data. You can store the data you need in a Variant data type, and the data will function appropriately due to casting performed by VBScript. It recognizes the type required by ADO, and converts the value in the Variant accordingly.


You cannot use on error goto <label> within VBScript.


VBScript supports some of the built-in Visual Basic functions such as Msgbox, Date, and IsNumeric. However, because VBScript is a subset of Visual Basic, not all built-in functions are supported. For example, VBScript does not support the Format function and the file I/O functions.




Here is an ADO Reference:
http://www.devguru.com/Technologies/ado/quickref/ado_intro.html

sample code:
http://www.planet-source-code.com/xq/ASP/txtCodeId.12050/lngWId.1/qx/vb/scripts/ShowCode.htm

tutorial:
http://www.sqlmag.com/Articles/Index.cfm?ArticleID=5909
0
 
LVL 4

Expert Comment

by:Gibble
ID: 6471404
'Here is a simple example

'declare variables
Dim objConn as new ADODB.Connection
Dim objRS as new ADODB.Recorset
Dim strConnectionString as String
Dim strSQL as String

'set a connection string to a database
strConnectionString = "ODBC;DSN=database"

'set a SQL query you want to use
strSQL = "Select * from sometable"

'open Connection
objConn.open strConnectionString

'open the record set
objRS.open strSQL , objConn

'disconnect the record set and close Connection
Set objRS.ActiveConnection = Nothing
ObjConn.Close

'use the recordset
While NOT objRS.eof
  'do something
  for i = 0 to objRS.Fields.Count - 1
    debug.print objRS.Fields(i).name & " = " & objRS.Fields(i).value
  next
Wend
0
 
LVL 4

Expert Comment

by:Gibble
ID: 6471405
While I was typing :(
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:rtcomp
ID: 6471411
I can use ADO with ASP with no problem. But the problem that I'm running into is I need to declare a function to update adatabase with out going to another asp page.
0
 
LVL 4

Accepted Solution

by:
Gibble earned 200 total points
ID: 6471458
Ah well why didn't you say that.
There are two options.

One is to include the function in the page and to call the same page with paramaters that will run the function.

Or you call another asp page that does the work but pass it an extra variable telling it what page you want it to return too.  At the end of that function redirect to the passed variable.

Unfortunately once the page is loaded on the clients machine you can't execute server side commands without calling a page on the server, this is because webpages once they are loaded are client based and can only talk to the server if they are called again or another is called.


Does this make sence?
0
 

Author Comment

by:rtcomp
ID: 6472173
Thats the answer I was looking for. Thanks.
0
 
LVL 4

Expert Comment

by:Gibble
ID: 6472230
No problem :D
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question