ASP操作access或sqlserver數(shù)據(jù)庫的函數(shù)庫
2018/6/21 17:35:47 字體:
大 中 小 瀏覽 3996
<%'*======================================
'* 名稱: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)閱讀
- 微信公眾號生成帶參數(shù)的二維碼asp源碼下載
- 返回上一頁頁面特效
- uni-app自定義loading組件
- 深山網(wǎng)吧留言板系統(tǒng)(激情穿越火線)v4.3
- css翻頁代碼
- 定制開發(fā)微信小程序的操作流程
- Asp加密解密函數(shù)
- 深山旅行社網(wǎng)站管理系統(tǒng)5.0發(fā)布
- 共有0條關(guān)于《ASP操作access或sqlserver數(shù)據(jù)庫的函數(shù)庫》的評論
- 發(fā)表評論