ASP操作access或sqlserver數(shù)據(jù)庫(kù)的函數(shù)庫(kù)
2018/6/21 17:35:47 字體:
大 中 小 瀏覽 3995
<%'*======================================
'* 名稱(chēng):useDb.asp
'* 功能:數(shù)據(jù)庫(kù)操作函數(shù)庫(kù)
'* 作者:intereye
'* 信箱:inteye@163.com
'* 主頁(yè):http://www.inteye.net
'* BLOG:http://blog.csdn.net/intereye
'*======================================
'* 函數(shù):openDb(dbType,dbUser,dbPass,dbName,dbServer,dbPath)
'* 功能:打開(kāi)數(shù)據(jù)庫(kù)連接
'* 參數(shù):dbType->數(shù)據(jù)庫(kù)類(lèi)型 MDB ACCESS數(shù)據(jù)庫(kù) || SQLSERVER SQLSERVER數(shù)據(jù)庫(kù)
'* 參數(shù):dbUser->訪(fǎng)問(wèn)數(shù)據(jù)庫(kù)用戶(hù)名
'* 參數(shù):dbPass->訪(fǎng)問(wèn)數(shù)據(jù)庫(kù)密碼
'* 參數(shù):dbName->數(shù)據(jù)庫(kù)名稱(chēng)
'* 參數(shù):dbServer->數(shù)據(jù)庫(kù)Host
'* 參數(shù):dbPath->數(shù)據(jù)庫(kù)路徑
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ù)庫(kù)中插入一條記錄
'* 參數(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ù)庫(kù)中指定的一條記錄
'* 參數(shù):tabname->數(shù)據(jù)表名
'* 參數(shù):dblist->數(shù)據(jù)庫(kù)字段名稱(chēng)數(shù)組
'* 參數(shù):fieldlist->表單變量名數(shù)組
'* 參數(shù):id->數(shù)據(jù)ID號(hào)
'* 返回: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ù)庫(kù)中刪除一條指定記錄
'* 參數(shù):tabname->數(shù)據(jù)表名稱(chēng)
'* 參數(shù):id->數(shù)據(jù)ID號(hào)
'* 返回: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ù)庫(kù)中取得一行
'* 參數(shù):tabname->數(shù)據(jù)表名
'* 參數(shù):fieldlist->數(shù)據(jù)字段數(shù)組
'* 參數(shù):caseStr->Sql條件語(yǔ)句
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ù)庫(kù)連接并釋放對(duì)象
Function CloseDb()
Conn.Close
Set Conn = Nothing
End Function
%>
- 相關(guān)閱讀
- [轉(zhuǎn)]javascript緩沖效果
- 南通美泰旅行社
- 利用javascript讓PNG透明圖片支持支持(IE6、IE7、firefox下測(cè)試通過(guò))
- asp利用hasOwnProperty驗(yàn)證某個(gè)json中的某個(gè)標(biāo)簽是否存在
- 工作室網(wǎng)站改版計(jì)劃
- 關(guān)于SQL2008 “不允許保存更改。您所做的更改要求刪除并重新創(chuàng)建以下表。您對(duì)無(wú)法重新創(chuàng)建的標(biāo)進(jìn)行了更改或者啟用了‘阻止保存要求重新創(chuàng)建表的更改’” 解決方案
- 青島景色旅程
- 旅行社手機(jī)網(wǎng)站模板12
- 共有0條關(guān)于《ASP操作access或sqlserver數(shù)據(jù)庫(kù)的函數(shù)庫(kù)》的評(píng)論
- 發(fā)表評(píng)論