利用ASP存取各種常用類型資料庫(4)
來源:互聯網
上載者:User
DBPath = "SourceDB=" & Server.MapPath( "DBC資料庫檔案名" )
' 串連資料庫
conn.Open Driver & SourceType & DBPath
Set CreateDbcRecordset = Server.CreateObject("ADODB.Recordset")
' 開啟資料表,參數二為Connection?對象
CreateDbcRecordset.Open "資料表名或Select語句", conn, 2, 2
End Function
5)將Excel97或Excel2000產生的XLS檔案(book)看成一個資料庫,其中的每一個工作表(sheet)看成資料庫表。
Function CreateExcelRecordset( XLS檔案名稱,Sheet名 )
Dim conn.Driver,DBPath
' 建立Connection對象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath( "XLS檔案名稱" )
' 調用Open 方法開啟資料庫
conn.Open Driver & DBPath
Set CreateExcelRecordset = Server.CreateObject("ADODB.Recordset")
' 開啟Sheet,參數二為Connection對象,因為Excel ODBC驅動程式無法直接用'sheet名來開啟sheet,所以請注意以下的select語句
CreateExcelRecordset.Open "Select * From ["&sheet&”$]”, conn, 2, 2
End Function
6)SQL Server屬於Server級的資料庫,使用時要求比較嚴格,必須要求輸入使用者名稱及密碼才能使用。
Function CreateSQLServerRecordset(電腦名稱,使用者ID, 使用者密碼,資料庫名稱 資料表或查看錶或Select指令 )
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="&資料庫名稱
Conn open Paras
Set CreateSQLServerRecordset = Server.CreateObject("ADODB.Recordset")