Tutorials to .com

Tutorials to .com » Asp » Database » Using ASP to access a variety of commonly used type of database (4)

Using ASP to access a variety of commonly used type of database (4)

Print View , by: iSee ,Total views: 10 ,Word Count: 774 ,Date: Mon, 25 May 2009 Time: 12:41 PM

Using asp to access a variety of commonly used type of database (4)

DBPath = "SourceDB =" & Server.MapPath ( "DBC database file name")
'Connect to database
conn.Open Driver & SourceType & DBPath
Set CreateDbcRecordset = Server.CreateObject ( "ADODB.Recordset")
'Open the data table, the second parameter object for Connection 
CreateDbcRecordset.Open "data sheets or Select statement", conn, 2, 2

End Function

5) Excel97 or XLS file Excel2000 generated (book) as a database, in which each worksheet (sheet) as a database table.

Function CreateExcelRecordset (XLS file name, Sheet name)

Dim conn.Driver, DBPath

'Connection object the establishment of
Set conn = Server.CreateObject ( "ADODB.Connection")
Driver = "Driver = (Microsoft Excel Driver (*. xls));"
DBPath = "DBQ =" & Server.MapPath ( "XLS file name")

'Call the Open method to open the database
conn.Open Driver & DBPath
Set CreateExcelRecordset = Server.CreateObject ( "ADODB.Recordset")
'Open the Sheet, the second parameter for the Connection object, because the Excel ODBC driver can not directly' sheet name to open the sheet, so please pay attention to
Under the select statement
CreateExcelRecordset.Open "Select * From [" & sheet &"$]", conn, 2, 2

End Function

6) SQL Server is Server-class database, use a more stringent requirement must be requested to enter a user name and password to use.

Function CreateSQLServerRecordset (computer name, user ID, user password, database name or to view data sheets or Select command)

Dim Params, conn

Set CreatSQLServerConnection = Nothing

Set conn = Server.CreateObject ( "ADODB.Connection")

Params = "Provider = SQLOLEDB.1"

Params = Params & "; Data Source =" & Computer

Params = Params & "; User ID =" & UserID

Params = Params & "; Password =" & Password

Params = Params & ". Initial Catalog =" & database name

Conn open Paras

Set CreateSQLServerRecordset = Server.CreateObject ( "ADODB.Recordset")

CreateSQLServerRecordset.Open source, conn, 2, 2

End Function

The use of the above function can be used to open the database type, and then use the Recordset object of ADO increase records, delete records, modify records, such as reactive
To be able to operate on the database. But note that in the actual development, we found that if the use of DBF, DBC, Excel databases, the implementation of the efficiency of not
MDB database of high efficiency, the best extent possible, the type of database MDB.

If used with DBF, DBC, Excel database, the following points should be noted: Excel can only read the database to increase the record, modify records, but can not be deleted in mind
Recorded; DBF, DBC <can read the record, an increase records, delete records, edit records, but records in the increase, the value of any field can be empty, which can be
Great to see the limitations, so as far as possible, using MDB or SQL database.

Fourth, an example (to access Excel data tables)

To further explain the usage of these functions, this paper gives an access to Excel data table examples, and other functions with similar access methods. Assuming that there is a
In Figure 2, known as the Excel file 1.xls, contains a group of three working table, a double shift, three shifts. To use the function below to access the work of the above table, "a group of" several
It is.

Figure 2

Preparation of ASP files (file name 1.asp) to access the Excel files.

Use IE and PWS (Personal Web Server), after browsing the results of Figure 3:

Figure 3


[1] DataBase and the World Wide Web Marianne Winslett, University of Illinois

[2] http://www.aspobjects.com

ASP Database Related Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.