What is this ??

L

Liza

Hi guys,

can anyone explain line number 5 to me. i don't quite understand what
is going on there and why.

1 <script language="vbscript" runat="server">sub Application_OnStart
2 getcustomers
3 end subsub getcustomers

4 set conn=Server.CreateObject("ADODB.Connection")
5 conn.Provider="Microsoft.Jet.OLEDB.4.0"
6 conn.Open "c:/webdata/northwind.mdb"
7 set rs=conn.execute("select name from customers")
8 Application("customers")=rs.GetRows
9 rs.Close
10 conn.Close
11 end sub</script>


also what is the meaning of the key word set here. is it an array? is
it a connection ( i ask this cos it gets "closed" later in line 9)

also i presume that customer would need to be declared somewhere as...
dim customers(aNumber). am i correct?

if so, how would i be sure that the size given to the "customers"
array would be big enough?
is there such thing as an array that can hold any number of elements
in ASP?



thanks guys.

Liza
 
B

Bob Barrows

Some of your questions go beyond what can be taught in a newsgroup post, but
I'll try. Here is the online ADO Programmers Guide:
http://msdn.microsoft.com/library/en-us/ado270/htm/pg_introduction.asp
Hi guys,

can anyone explain line number 5 to me. i don't quite understand what
is going on there and why.

1 <script language="vbscript" runat="server">sub Application_OnStart
2 getcustomers
3 end subsub getcustomers

4 set conn=Server.CreateObject("ADODB.Connection")
5 conn.Provider="Microsoft.Jet.OLEDB.4.0"

ADO (ActiveX Data Objects) is the technology used to allow your
vbscript/jscript/vb/etc. code to interface with databases. It consists of
several COM objects that expose the methods and properties required to work
with data from various databases. OLEDB is the name of the code foundation
that is used by ADO objects. OLEDB connects to various databases via the use
of Providers which can come from Microsoft (these are included in the
Microsoft Data Access Components (MDAC) installation package available from
www.microsoft.com/data - MDAC is automatically installed with later versions
of IE and is included as part of the operating system in Windows 2000/XP and
later), or from non-MS database suppliers. There is an older database
technology called ODBC which can still be used in ADO using the MS OLEDB
Provider for ODBC (MSDASQL), but this is not recommended because it forces
you to use two software layers to get to your data (OLEDB and ODBC).
Instead, you should use the native Providers for your specific database.

In this case, it looks like you're attempting to connect to an Access (Jet)
database, using the native Jet OLEDB version 4.0 provider. You can find many
examples of connection strings at www.able-consulting.com/ado_conn.htm.

6 conn.Open "c:/webdata/northwind.mdb"
7 set rs=conn.execute("select name from customers")
8 Application("customers")=rs.GetRows
9 rs.Close
10 conn.Close
11 end sub</script>


also what is the meaning of the key word set here. is it an array? is
it a connection ( i ask this cos it gets "closed" later in line 9)

In general, "set" is used to cause a variable to refer to a binary object
(usually a COM object), so that the variable behaves as if it WAS that
binary object. In line 4 it was used to cause conn to refer to an ADODB
Connection object that was returned by the CreateObject method. In line 7,
it is being used to cause the variable called rs to refer to the ADODB
Recordset object that is being returned by the Connection object's Execute
method.

In line 8, an Application variable is being set to the array that is being
returned from the Recordset object's GetRows method.
also i presume that customer would need to be declared somewhere as...
dim customers(aNumber). am i correct?

No, Application and Session variables do not need to be declared. Once
created, they are available to any page belonging to the Application or
Session. Do not be tempted to store ADO objects in Application or Session:
it may be counter-intuitive, but storing a "global" COM object can severely
impair an application's performance since only one page at a time will be
able to use it.
if so, how would i be sure that the size given to the "customers"
array would be big enough?

The array returned by GetRows is created behind the scenes: you do not have
to worry about sizing it.
is there such thing as an array that can hold any number of elements
in ASP?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbsvariables.asp

Do you have the vbscript documentation? here is the link where you can
download it:
http://tinyurl.com/7rk6

Here are some good asp resources:
www.learnasp.com
www.4guysfromrolla.com
www.aspfaq.com
www.asp101.com

HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top