The statements are the same as those for connecting to access and SQL server. You can change them a little bit:
Dim objconn, mydsn
If not isobject (objconn) then
Set objconn = server. Createobject ("ADODB. Connection ")
Mydsn = "provider = oraoledb. Oracle; Data Source = oracle_shanghai; user id = Scott; Password = tiger; persist Security info = true"
Objconn. Open mydsn
End if
============
''Connection string Initialization
Select case datatype
Case 0 ''access
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & dbpath
Case 1 ''SQL
Connstr = "provider = sqloledb; user id =" & dbusername & "; Password =" & dbpassword & "; initial catalog =" & dbdatabase &"; data Source = "& dblocalname &";"
End select
==== Excel
ASP connection Excel
Some customers do not need to use the database for various reasons, but use Excel!
So here are two examples of connecting to excel. Simply put, Excel is used as a database.
Method 1:
Example of ASP reading Excel files
<% & Apos; in the following example, the Excel file name is list.xls and the worksheet name is sheet1.
Dim Conn
Dim strconn
Dim rs
Dim SQL
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "driver = {Microsoft Excel Driver (*. xls)}; DBQ =" & server. mappath ("list.xls ")
Conn. Open strconn
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from [sheet1 $]"
Rs. Open SQL, Conn, 2, 2
%>
<Center>
<Table border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<%
For I = 0 to Rs. Fields. Count-1
%>
<TD width = "1" bgcolor = "# cccccc"> </TD>
<TD Height = "28" bgcolor = "# 0099ff"> <Div align = "center"> <% = RS (I ). name %> </div> </TD>
<%
Next
%>
<TD width = "1" bgcolor = "# cccccc"> </TD>
</Tr>
<%
Do while not Rs. EOF
%>
<Tr>
<%
For I = 0 to Rs. Fields. Count-1
%>
<TD width = "1" bgcolor = "# cccccc"> </TD>
<TD Height = "28" valign = "bottom"> <% = RS (I) %> </TD>
<%
Next
%>
<TD width = "1" bgcolor = "# cccccc"> </TD>
</Tr>
<Tr>
<% & Apos; generate a blank line with a height of 1 (horizontal line)
For I = 0 to Rs. Fields. Count-1
%>
<TD Height = "1" bgcolor = "# cccccc"> </TD>
<TD Height = "1" bgcolor = "# cccccc"> </TD>
<%
Next
%>
<TD width = "1" bgcolor = "# cccccc"> </TD>
</Tr>
<%
Rs. movenext
Loop
Rs. Close
Set rs = nothing
Conn. Close
Set strconn = nothing
%>
</Table>
</Center>
Method 2:
<%
& Apos; ================================ ASP read Excel note ============================ ==================
& Apos; I) regards the xls file (book) generated by excel97 or excel2000 as a database, and each Worksheet (sheet) in it as a database table
& Apos; ii) ADO assumes the name of the first row in Excel. Therefore, you must include the content of the first row in the defined range.
& Apos; iii) the row title (field name) in Excel cannot contain numbers. The Excel driver will encounter errors in this case. For example, your line title is "f1"
& Apos; iiii) If a column in your Excel worksheet contains both text and numbers, the ODBC driver of Excel cannot process the data type of this row, make sure that the data type of this column is consistent.
& Amp; apos; E-MAIL: Kaxue@Hotmail.com QQ: 484110 homepage: www.flyday.net
& Apos; Sorting time: Thursday, May 23,200 PM win2000server + iis5 passed the test
& Apos; ========================================================== ======================================
Dim Conn, driver, dbpath, RS
& Apos; create a connection object
Set conn = server. Createobject ("ADODB. Connection"
Driver = "driver = {Microsoft Excel Driver (*. xls )};"
Dbpath = "DBQ =" & server. mappath ("test.xls ")
& Apos; call the Open Method to open the database
Conn. Open driver & dbpath
& Apos; DSN connection method
& Amp; apos; Conn. Open "DSN = test"
& Apos; note that the table name must be written in the following format: "[Table Name $ ]"
SQL = "select * from [sheet1 $] where no. = 0"
Set rs = conn. Execute (SQL)
If Rs. EOF and Rs. bof then
Response. write "the data you need is not found !! "
Else
Do while not Rs. EOF
Response. Write RS ("name"
Rs. movenext
Loop
End if
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
& Apos; response. Write "successful! "
%>
--- Wangle: 20:46:47 ---