ASP操作access或sqlserver數(shù)據(jù)庫的函數(shù)庫
2018/6/21 17:35:47 字體:
大 中 小 瀏覽 3989
<%'*======================================
'* 名稱:useDb.asp
'* 功能:數(shù)據(jù)庫操作函數(shù)庫
'* 作者:intereye
'* 信箱:inteye@163.com
'* 主頁:http://www.inteye.net
'* BLOG:http://blog.csdn.net/intereye
'*======================================
'* 函數(shù):openDb(dbType,dbUser,dbPass,dbName,dbServer,dbPath)
'* 功能:打開數(shù)據(jù)庫連接
'* 參數(shù):dbType->數(shù)據(jù)庫類型 MDB ACCESS數(shù)據(jù)庫 || SQLSERVER SQLSERVER數(shù)據(jù)庫
'* 參數(shù):dbUser->訪問數(shù)據(jù)庫用戶名
'* 參數(shù):dbPass->訪問數(shù)據(jù)庫密碼
'* 參數(shù):dbName->數(shù)據(jù)庫名稱
'* 參數(shù):dbServer->數(shù)據(jù)庫Host
'* 參數(shù):dbPath->數(shù)據(jù)庫路徑
Function openDb(dbType,dbUser,dbPass,dbName,dbServer,dbPath)
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Select case dbType
case "MDB":
connStr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(""&dbPath&dbName&"")
case "SQLSERVER":
connStr = "Provider=SQLOLEDB.1;Password="&dbPass&";Persist Security Info=True;User ID="&dbUser&";Initial Catalog="&dbName&";Data Source="&dbServer&""End Select
Conn.Open connStr
End Function
'* 函數(shù):add(tabname,fieldlist,dblist)
'* 功能:在數(shù)據(jù)庫中插入一條記錄
'* 參數(shù):tabname->數(shù)據(jù)表名
'* 參數(shù):dblist->數(shù)據(jù)表字段名數(shù)組
'* 參數(shù):fieldlist->表單變量名數(shù)組
'* 返回:0 false || 1 true
Function add(tabname,dblist,fieldlist)
Sql = "Insert INTO "&tabname&"("
Value = ""
Field = ""
For Each v in dblist
Field = Field & v & ","
Next
Field = Left(Field,Len(Field)-1)
Value = Field & ") VALUES("
For Each v in fieldlist
If Request.Form(v) <> "" Then
Value = Value & "'" & Request.Form(v) & "',"
Else
Value = Value & "'" & v & "',"
End If
Next
Value = Left(Value,Len(Value)-1)
Sql = Sql & Value & ")"
Conn.Execute(Sql)
CloseDb()
If Err Then
add = 0
Else
add = 1
End If
End Function
'* 函數(shù):update(tabname,dblist,fieldlist,id)
'* 功能:更新數(shù)據(jù)庫中指定的一條記錄
'* 參數(shù):tabname->數(shù)據(jù)表名
'* 參數(shù):dblist->數(shù)據(jù)庫字段名稱數(shù)組
'* 參數(shù):fieldlist->表單變量名數(shù)組
'* 參數(shù):id->數(shù)據(jù)ID號
'* 返回:0 false || 1 true
Function update(tabname,dblist,fieldlist,id)
Sql = "Update " & tabname & " Set "
Value = ""
For i=0 to ubound(dblist)
Value = Value & dblist(i) & "='"
If Request.Form(fieldlist(i)) <> "" Then
Value = Value & Request.Form(fieldlist(i)) & "',"
Else
Value = Value & fieldlist(i) & "',"
End If
Next
Value = Left(Value,Len(Value)-1)
Sql = Sql & Value & " Where id=" & id
Conn.Execute(Sql)
CloseDb()
If Err Then
update = 0
Else
update = 1
End If
End Function
'* 函數(shù):del(tabname,id)
'* 功能:從數(shù)據(jù)庫中刪除一條指定記錄
'* 參數(shù):tabname->數(shù)據(jù)表名稱
'* 參數(shù):id->數(shù)據(jù)ID號
'* 返回:0 false || 1 true
Function del(tabname,id)
Sql = "Delete FROM " & tabname & " Where id in(" & id & ")"
Conn.Execute(Sql)
CloseDb()
If Err Then
del = 0
Else
del = 1
End If
End Function
'* 函數(shù):getRow(tabname,fieldlist,caseStr)
'* 功能:從數(shù)據(jù)庫中取得一行
'* 參數(shù):tabname->數(shù)據(jù)表名
'* 參數(shù):fieldlist->數(shù)據(jù)字段數(shù)組
'* 參數(shù):caseStr->Sql條件語句
Function getRow(tabname,fieldlist,caseStr)
If Not isArray(fieldlist) Then
fieldlist = "*"
Else
Field = ""
For Each val in fieldlist
Field = Field & val & ","
Next
fieldlist = Left(Field,Len(Field)-1)
End If
Sql = "Select " & fieldlist & " FROM " & tabname & caseStr
Set Rs = Conn.Execute(Sql)
If Rs.Eof AND Rs.Bof Then
getRow = 0
Else
getRow = 1
End If
End Function
'* 函數(shù):CloseDb()
'* 功能:關(guān)閉數(shù)據(jù)庫連接并釋放對象
Function CloseDb()
Conn.Close
Set Conn = Nothing
End Function
%>
- 相關(guān)閱讀
- 景點門票預(yù)訂
- 12個定律原則
- 深山行者留言系統(tǒng)V2.2 .1 更新下載
- JS自動格式化輸入的數(shù)字/千位分隔符
- 深山留言板警察出動效果
- asp隨機顯示字符長度與類型(可隨機顯示數(shù)字、小寫字母、大寫字母,可以做為隨機密碼使用)
- 網(wǎng)站提示錯誤頁面,幾秒后返回首頁
- asp實現(xiàn)獲得當(dāng)前文章的上一篇信息與下一篇信息功能及代碼
- 共有0條關(guān)于《ASP操作access或sqlserver數(shù)據(jù)庫的函數(shù)庫》的評論
- 發(fā)表評論