直播中
Dim conn,Provider,DBPath
‘ 建立Connection 對(duì)象
Set conn = Server.CreateObject("ADODB.Connection")
Provider = "Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath = "Data Source=" & Server.MapPath( "數(shù)據(jù)庫(kù)文件名" )
‘ 連接數(shù)據(jù)庫(kù),注意下面一行帶有密碼參數(shù)
conn.Open Provider & DBPath&”Jet OLEDB:Database Password=”&assword
Set CreateSecuredMdbRecordset = Server.CreateObject("ADODB.Recordset")
‘ 打開(kāi)數(shù)據(jù)表,參數(shù)二為Connection對(duì)象
CreateSecuredMdbRecordset.Open "數(shù)據(jù)表名", conn, 2, 2
End Function
3)DBF文件不是一個(gè)標(biāo)準(zhǔn)的數(shù)據(jù)庫(kù)文件,只相當(dāng)于標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)文件中的一個(gè)數(shù)據(jù)表,所以為了使用DBF文件,采用把所有的DBF文件放在一個(gè)目錄下,這樣把目錄名看成標(biāo)準(zhǔn)數(shù)據(jù)中的數(shù)據(jù)庫(kù)表,每一個(gè)DBF文件相當(dāng)于標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)的數(shù)據(jù)表。下面函數(shù)中Directory是DBF所在的目錄名,
Function CreateDbfRecordset( 目錄名, DBF文件名或Select語(yǔ)句 )
Dim conn,Driver,SourceType,DBPath
‘ 建立Connection 對(duì)象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBF;"
DBPath = "SourceDB=" & Server.MapPath( "目錄名" )
‘ 調(diào)用Open 方法打開(kāi)數(shù)據(jù)庫(kù)
conn.Open Driver & SourceType & DBPath
Set CreateDbfRecordset = Server.CreateObject("ADODB.Recordset")
‘ 打開(kāi)DBF文件,參數(shù)二為Connection對(duì)象
CreateDbfRecordset.Open DBF文件名或Select語(yǔ)句, conn, 2, 2
End Function
4)由Foxpro生成的DBC數(shù)據(jù)庫(kù)與MDB數(shù)據(jù)庫(kù)相似,都是一個(gè)數(shù)據(jù)庫(kù)包含幾個(gè)數(shù)據(jù)表的形式,所以對(duì)DBC數(shù)據(jù)庫(kù)的存取方法與MDB數(shù)據(jù)庫(kù)相似。
Function CreateDbcRecordset( DBC數(shù)據(jù)庫(kù)文件名, 數(shù)據(jù)表名或Select語(yǔ)句 )
Dim conn,Driver,SourceType,DBPath
‘ 建立Connection 對(duì)象
Set conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBC;"