Dynamic Web Design: 11 Ways for ASP to connect to a database

Source: Internet
Author: User
Dynamic | Connection Database | design | Web page design ASP Connection 11 ways-This article summarizes the use of ASP links to various methods:

1.Access dsn-less Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adoconn. Open "Driver={microsoftaccessdriver (*.mdb)};D bq=" &_
Server.MapPath ("path")

2.AccessOLEDB Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Datasource=" &server.mappath ("path")

3.SQLserver Connection method:

Setadocon=server.createobject ("Adodb.recordset")
ADOcon. Open "driver={}; server= (local); uid=***; pwd=***; " &_
"Database= name;"

4.SQLserverOLEDB Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "PROVIDER=SQLOLEDB.1;DATASOURCE=RITANT4;" &_
"userid=***; password=***; " &_
"Initalcatalog= name"


5.Oracle Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Driver={microsoftodbcfororacle};server=oraclesever.world;uid=admin;pwd=pass;"

6.OracleOLEDB Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Provider=oraoledb.oracle;datasource=dbname;userid=admin;password=pass;"

7.dBase Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Driver={microsoftdbasedriver (*.dbf)};d riverid=277;dbq=------------;"

8.mySQL Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "driver={};d atabase=yourdatabase;
uid=username;pwd=yourpassword;option=16386; "

9.VisualFoxpro Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "DRIVER={MICROSOFTVISUALFOXPRODRIVER};SOURCETYPE=DBC;SOURCEDB=*.DBC; Exclusive=no; "

10.MStext Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Driver={microsofttextdriver (*.txt;*.csv)};d bq=-----;" &_
"Extensions=asc,csv,tab,txt; Persistsecurityinfo=false; "

11.MStextOLEDB Connection method:

Setadocon=server.createobject ("Adodb.connection")
Adocon.open "Provider=microsof.jet.oledb.4.0;datasource=your_path;" &_
"ExtendedProperties ' text"; Fmt=delimited ' "



< two > commonly used SQL commands in four types:

1. Query data records (SELECT)
Syntax: Select field serial fromtablewhere field = Content
Example: To find all the records of the author as "Cancer" from the Book table, the SQL statement reads as follows:

Select*frombookwhereauthor= ' cancer '

"*" is to remove all the fields from the Book table, such as the query's field value is a number, then the "content" will not need to add a single quotation mark, as the date, in Access in (#) included, and in SQL Server is included in ('),
Such as:

Select*frombookwhereid=1
select*frombookwherepub_date= #2002 -1-7# (Access)
Select*frombookwherepub_date= ' 2002-1-7 ' ()

Tips:
Date function to_date is not a standard SQL, not all applicable, so we should refer to the specific syntax when using

In addition, if you are querying incoming variables, the following are:

Strau=request.form ("author")
Strsql= "Select*frombookwhereauthor= '" &strau& ""

If the query is a number, then:

Intid=request.form ("id")
Strsql= "Select*frombookwhereid=" &intid

In many, such as Oracle, the above statement can be written as:

Strsql= "Select*frombookwhereid= '" &intID& ""

But character types must not be written in digital format, and need to be noted.


2. Add record (Insert)
Grammar:

Insertintotable (Field1,field2,....) Values (value1,value2,....)

Example: Add an author is a "cancer" record in Book table:

Insertintobook (Bookno,author,bookname) VALUES (' CF001 ', ' cancer ', ' Cancer no component Upload program ')

Similarly, if you use a variable as follows:

Strno=request.form ("Bookno")
Strau=request.form ("author")
Strname=request.form ("BookName")
Strsql= "Insertintobook (bookno,author,bookname) VALUES (' &strno&" ', ' "&strau&" ', ' ", '" &strname & "')"

3. Methods of inserting data using the AddNew of a Recordset object:
Grammar:

Rs.addnew
RS ("Field1"). value=value1
RS ("Field2"). Value=value2
...
Rs.update

4. Modify data records (Update)
Grammar:

Updatetablesetfield1=value1,field2=value2,... Wherefieldx=valuex

Example:

Updatebooksetauthor= ' Babycrazy ' wherebookno= ' CF001 '

If you use a variable as follows:

Strno=request.form ("Bookno")
Strau=request.form ("author")
Strsql= "Updatebooksetauthor= '" &strau& "' wherebookno= '" &strno ""


The Update method for the 5.Recordset object:
Grammar:

RS ("Field1"). value=value1
RS ("Field2"). Value=value2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.