Feed on
Subscription

In library of the service data in ASP

ASP has a the mainest function,It is it can make you special easily join database.It is normally with an Access or database of a SQL is linked together.Because Access is the easiest,start,At the same time,Perhaps had contained on your machine Access,So,In the example below,We come to use Access make case.Once you learned ASP and technics of core of Access database connective,When you begin to use SQL Server,You can discover,The crucial technology that both place needs is basic and identical.

Turn from:Dynamic net makes guideline Www.knowsky.com
When you want join database,You need in server admiral this database is opened.You can carry name of service data source (DSN) method of connective of a DSN-less is used to join and open a database directly in perhaps adopting the script language in you.

Establish name of source of a data (DSN)
The database that you can give you through be in Control Panel builds DSN of a system to make your database can be in ASP join is used.You can be built on your this locality computer a certain number of DSN,The different database that you use every DSN correspondence.After building DSN,You can go up in your this locality server checked your page.If your website is by

ISP provides a service,And this ISP supports ASP,So very possible it can offer port of a GUI,The database that comes to you founds a DSN.

In Windows 95/98/NT,Open Control Panel (begin bill of fare - %26gt; setting - %26gt; Control Panel) ,Doubleclick ODBC to enter.
Selection system DSN,Click Add.
Choose " Microsoft Access Driver " ,Click an end.
Fill in data source name.This is you to the name since your database,Mix so an Alias is similar operation.
Choice pushbutton is clicked in database choice,The position that the Access database that you found in the system that browse deposits.
Click OK
Now,New DSN can show in systematic DSN now,And can be on your this locality server used.

Join database
Let us build a DSN-less to join,And look be how to join of the database.When you found a DSN,You had stored about a few information of this database,So you do not need to repeat them when needing to use a few information every time,These information if:Database type, name, deposit place and optional sex, user and password.

Should found a DSN-less to join,You provide same information with respect to need.This example showed the database that how calls Products to builds a DSN-less to join below:

%26lt;%
StrConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Db\products.mdb "
Set ObjConn = Server.CreateObject ("ADODB.Connection" )
ObjConn.OpenStrConnect
%%26gt;

The second drive that defined a database and physical method.To want to use a DSN-less to join,You know with respect to need actual document deposits a place (absolutely method) .The person that Server.MapPath serves to any use lead plane offerred a simple working environment to search the actual visit way that gives those to be hard to check.

If we had built DSN of a system,Name for Products,Join the code should is:

%26lt;%
Set ObjConn = Server.CreateObject ("ADODB.Connection" )
ObjConn.Open "products "
%%26gt;

Now,The database had been opened,So what can you do?The first thing reads a series of records in the database namely of course,Go in the page that puts them you.But,Before this,You need a Recordset.

Recordset
A Recordset is memory expresses all information that go up in special database.So,When you open this Recordset,The content of all travel in the watch and row is can visit.You need to open this Recordeset,You need no less than like opening a database to join.Their command is similar:

Set ObjRec = Server.CreateObject ("ADODB.Recordset" )
ObjRec.Open "downloadable" , strConnect, 0, 1, 2

This statement founded a Recordset(objRec) that the name expresses for Downloadable,This watch is defined in the StrConnect of Products database.Use Recordset Open, we can scan this list circularly,And can show all its content go up to screen.Or,The content that we can check specific field,The content that also can pay close attention to us only writes screen to go up.

Each represent a field.So,If the database expresses following place to show:

Product ID

SKU

Name

File

1

PR12345

Product A

Install_a.exe

2

PR12346

Product B

Install_b.exe


So,The content that we are like next fields:ProductID, SKU, name, with File.Your watch can have a lot of additional field content probably,The likelihood includes a lot of things,Be like the price or product (commodity) description.But the idea that this sketch map can give you to offer the basiccest database to express.

Fill in Recordset content
Use Recordset is a very easy thing.If you want to browse a database circularly,Print all information show to screen,You are OK according to below will operate:

While NOT ObjRec.EOF
' Says To Do This As Long As We Haven't Reached The End Of The File
Response.WriteobjRec("ProductID") %26 " , response.WriteobjRec("ProductID") %26 " ,,
Response.WriteobjRec("SKU") %26 " , response.WriteobjRec("SKU") %26 " ,,
Response.WriteobjRec("Name") %26 " , response.WriteobjRec("Name") %26 " ,,
Response.WriteobjRec(%26quot;File%26quot;) %26amp; %26quot;%26lt;BR%26gt; %26quot;
ObjRec.MoveNext
Wend;
Although if this has used Loop,you are done not have,You still can keep information in Comma-delimited string through reading this code,When and become a new travel was being founded in database watch,Found a new travel afresh,Come to a that in record sheet.You can use same method to keep data in HTML form to go.Through using Response.Write to add your TABLE label,Need remembers the following:

The content in your HTML label and quote.
If your label or content used quote,The attention uses double quote:
%26lt;FONT SIZE=%26quot;%26quot;+2%26quot;%26quot;%26gt; .
Use %26 will join variable and HTML/ content information
Choose the field in Recordset
The field that assumes our Products database includes to call OS likewise,Assume this field is accord with of dividing line of a platform.Same,The data that lets us store the data in this field can be to be as follows only suppose:Windows NT, windows 95, windows 98, windows, mac, unix, or Linux.

Below,We can affirm we need the field prints which to screen,And want oversight those what fields.Or,We can choose what field with a kind of format,And the form that another fields use other,Like,Use different color.

Use a simple If. . . ,Can offer more databases to control the right to us circularly.The record that lets us print product of concerned Windows NT above all:


%26lt;TABLE BORDER=0 WIDTH=600%26gt;

%26lt;TR%26gt;%26lt;TD COLSPAN=4 ALIGN=CENTER%26gt;%26lt;FONT SIZE=%26quot;+1%26quot;%26lt;%26lt;B%26gt;Windows NT Products%26lt;/B%26gt;%26lt;/FONT%26gt;%26lt;/TD%26gt;%26lt;/TR%26gt;

%26lt;%
While NOT ObjRec.EOF

If ObjRec("OS") = "Windows NT" THEN ' Specifies The Criteria

Response.Write %26quot;%26lt;TR%26gt;%26lt;TD BGCOLOR=%26quot;%26quot;#FFFF66%26quot;%26quot;%26gt;%26quot; %26amp; ObjRec(%26quot;ProductID%26quot;) %26amp; %26quot;%26lt;/TD%26gt; %26quot;
Response.Write %26quot;%26lt;TD%26gt;%26quot; %26amp; ObjRec(%26quot;SKU%26quot;) %26amp; %26quot;%26lt;/TD%26gt; %26quot;
Response.Write %26quot;%26lt;TD%26gt;%26quot; %26amp; ObjRec(%26quot;Name%26quot;) %26amp; %26quot;%26lt;/TD%26gt; %26quot;
Response.Write %26quot;%26lt;TD%26gt;%26quot; %26amp; ObjRec(%26quot;File%26quot;) %26amp; %26quot;%26lt;/TD%26gt;%26lt;/TR%26gt; %26quot;

End If
ObjRec.MoveNext
Wend

%%26gt;
%26lt;/TABLE%26gt;
Add a record
Once you began to use Recordset and ASP,You can hope to be able to pass a network to add data in the database to go very.Adding content is very important,Like,The point of view that leaves them when the person that you need your webpage to browse and view,Or,When you want to undertake administrative updating.


The code below opened a Recordset,This Recordset is the database form that having book and their author name about.You once may have seen this,But this,The kind of pressing with a finger that three manuals define finally is different:AdOpenStatic, adLockOptimistic, adCmdTable:

%26lt;% ' Database Connection Already Made; Code Not Shown Here
Set ObjRec = Server.CreateObject ("ADODB.Recordset" )
ObjRec.Open "books" , bookdb, adOpenStatic, adLockOptimistic, adCmdTable
%%26gt;

(If you do not have the duplicate file of use Adovbs.inc,The third should is:ObjRec.Open "books" , bookdb, 3, 3, 2) .

Recordset gets ready now receive data,You need to tell it what to add only.Below this circumstance,Assume we take out variable from inside form:StrBookTitle and StrBookAuthor.Our Table, books has two fields,Call Title and Author,So we can add a new record through using the statement below:

%26lt;%
ObjRec.AddNew
ObjRec("Title") = StrBookTitle
ObjRec("Author") = StrBookAuthor
ObjRec.Update
%%26gt;

StrBookTitle and StrBookAuthor delegate are worth,Be visited by the user normally.If you just want to check Add function,You can add a variable to Title and Author -- just need to remember using quote.When you use it for the first time,The database that you may open you instantly,The happening that updates in order to ensure.

Recordset type
In indication ObjRec.Open case,Your meeting discovery has 0 in fine,1,The model of written characters of 2.Type of these digital representing's different pressing with a finger.You are used type relies on you to will use it what to do.For example,If you do not need to revise or increase any record,You can use type of a Lock.And when when you the plan should be revised or updating a database,The kind that you select can differ.

0, 1, 2 is represented actually:

AdOpenForwardOnly, adLockReadOnly, adCmdTable

Of course,The backup that if be on your server,had had Adovbs.inc,So,You also need not use a number,Use these words directly.A list that Adovbs.inc included these three constant and other constant.

Related:

    Submit: