<% '数据库操作函数包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 %>
|