<% '數據庫操作函數包DatabasePackage
'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 '********************** '目的:取得各種數據庫連接字符串 '輸入:數據庫服務器名、數據庫名、用戶ID、密碼 '輸出:數據庫連接字符串 '********************** Function GetConnStr(pServer,pDb,pId,pPwd,pType) Dim strConn strConn = "" if pType="SQLSERVER" then strConn = "Driver={SQL Server};Server=" & pServer & ";Database=" & pDb strConn = strConn & ";Uid=" & pId & ";Pwd=" & pPwd & ";" end if
if pType="ACCESS" then strConn = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath(pDb) strConn = strConn & ";password=" & pPwd end if
if pType="EXCEL" then strConn = "Driver={Microsoft Excel Driver (*.xls)};" & "DBQ=" & Server.MapPath(pDb) end if
GetConnStr = strConn
End Function '**********************
'********************** '目的:返回客戶名稱 '輸入:客戶ID '輸出:客戶名稱 '********************** Function GetCustomerName(ID)
dim cn dim rs dim strSQL
set cn=server.CreateObject("ADODB.Connection") set rs=server.CreateObject("ADODB.RecordSet")
cn.Open Application("ConnStr")
strSQL="select UserName from P_User_Info where Id=" & ID rs.Open strSQL,cn if rs.EOF then GetCustomerName="" else GetCustomerName=rs("UserName") end if
rs.Close cn.Close set rs=nothing set cn=nothing End Function '**********************
'********************** '目的:判斷表中某字段值是否已經存在 '輸入:表名、字段名、關鍵字 '輸出:true or false '********************** Function IsExist(TableName,FieldName,FieldValue)
dim cn dim rs dim blnTemp dim strconn
set cn = server.CreateObject("ADODB.Connection") set rs = server.CreateObject("ADODB.Recordset")
strconn = GetConnStr(cnstDataSvr,cnstDataName,cnstUserId,cnstUserPwd,"SQLSERVER") cn.open strconn with rs .open "select " & FieldName & " from " & TableName & " where " & FieldName & "='" & FieldValue & "'",cn blnTemp = not .EOF .close end with cn.close set rs = nothing set cn = nothing
IsExist = blnTemp
End Function '**********************
'********************** '目的:事務處理更新後臺數據 '輸入:SQL執行字符串和錯誤信息字符串 '輸出:true or false '********************** Function ExecuteUpdate(strSQL) dim cn,strconn ExecuteUpdate = false set cn = server.CreateObject("ADODB.Connection") strconn = GetConnStr(cnstDataSvr,cnstDataName,cnstUserId,cnstUserPwd,"SQLSERVER") cn.open strconn on error resume next cn.begintrans cn.Execute strSQL if cn.errors.count>0 then cn.rollbacktrans else cn.committrans ExecuteUpdate = true end if cn.Close set cn = nothing End Function '**********************
'********************** '目的:取字段預定義值 '輸入:數據庫連接,字段中文名,字段中文值 '輸出:字符串 'ts_TypeColValue:字段預定義常數表 '********************** Function getFieldValue(pConn,pTable,pField,pValue) dim strSql,rstmp set rstmp = server.createobject("adodb.recordset")
strSql = "select * from ts_TypeColValue where TableName=" & pTable strSql = strSql & " and ColCnNm=" & pField & "and TypeColName=" & pValue rstmp.open strSql,pConn,1,3 if rstmp.recordcount>0 then getFieldValue = rstmp("TypeColVal") else getFieldValue = "" end if rstmp.close set rstmp = nothing End Function '**********************
'DatabasePackage End %>
|