Data | Database 6 SQL Server is a server-level database that is strictly used and requires you to enter a username and password to use.
Function createsqlserverrecordset (computer name, user ID, user password, database name data table or view table or select instruction)
Dim Params, Conn
Set creatsqlserverconnection = Nothing
Set conn = Server.CreateObject ("ADODB. Connection ")
Params = "Provider=SQLOLEDB.1"
Params = Params & ";D ata 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
Using the above function can open a common type of database, and then use ADO Recordset object to add records, delete records, modify records and other functions can operate on the database. But to illustrate, in the actual development we found that, if the use of DBF, DBC, Excel database, the efficiency of the implementation of the MDB database is not efficient, it is best to use the MDB type database as much as possible.
If you use DBF, DBC, Excel database, the following points to note: Excel database can only read, add records, modify records, but not delete records; DBF, dbc< can read records, add records, delete records, modify records, but when adding records, None of the field values can be empty, which shows that the limitations are great, so use an MDB or SQL database as much as possible.
Iv. examples (accessing Excel data Tables)
To further illustrate the use of these functions, this article gives an example of accessing Excel data tables, and other functions are accessed in a similar way. Suppose you have an Excel file named 1.xls in Figure 2, which contains three worksheets, one, two, and three. Below you need to use the above function to access the worksheet "class" data.
Write an ASP file (file name 1.asp) to access this Excel file.
Here is the ASP source code:
<%
' Create a Connection object
Function Createexcelrecordset (Xlsfile,sheet)
Dim Rs,conn,driver,dbpath
Set conn = Server.CreateObject ("ADODB. Connection ")
Driver = "Driver={microsoft Excel Driver (*.xls)};"
DBPath = "dbq=" & Server.MapPath ("Xlsfile")
' Call the Open method to connect to the database
Conn. Open Driver & DBPath
Set createexcelrecordset = Server.CreateObject ("ADODB. Recordset ")
' Open sheet table, parameter two ' >connection object
Createexcelrecordset.open "SELECT * FROM [" &sheet& "$]", Conn, 2, 2
End Function
%>
<HTML>
<body bgcolor= "#FFFFFF" >
<table border=1>
<tr bgcolor= #00FFFF >
<%
' Bank is a key line, a reference to a function
' Set Rs=createexcelrecordset ("1.xls", "one Class")
Part I outputs "Table header name" and the background color of the header is #00ffff
' For i=0 to Rs. Fields.count-1
Response.Write "<TD>" & RS (i). Name & "</TD>"
Next
%>
</TR>
<%
"Contents" of the ' part ' > Output datasheet
Rs. MoveFirst ' moves the current data record to the first item
While not Rs. EOF ' to determine if the last item was passed
Row = "<TR>"
For i=0 to Rs. Fields.count-1
row = row & "<TD>" & RS (i) & "</TD>"
Next
Response.Write Row & "</TR>"
Rs. MoveNext ' Move to the next item
Wend
%>
</TABLE></CENTER>
</BODY>
</HTML>
After using IE and PWS (Personal Web Server), browse the results as shown in Figure 3:
Reference documents:
[1] DataBase and the World Wide Web Marianne Winslett, University of Illinois
[2]http://www.aspobjects.com