首页 > ASP操作MSQL类

ASP操作MSQL类

<%
'=========================================================
'類名: Ms SQL 操作類
'作者: Athrun
'版本: V 0.1
'開發日期:2012-4-14
'修改日期:2012-4-14
'Email: [email protected]
'Dim Db,ProcName,Prams,Rs,OutPut,Sql
'Set Db = New DbHelperSQL
'ProcName = "SP_Name"
'Db.ParameterClear()
'Db.ParameterAdd "@EID",3,2,4,EID
'Db.ProcExecute(ProcName)
'=========================================================
'Const dbIP = "127.0.0.1SQLEXPRESS"
'Const dbname="HandyMan"
'Const dbuid="sa"
'Const dbpwd="sasa"
'Const AdoConnectionTimeout = 15
'Const AdoCommandTimeout = 30Class DbHelperSQLPrivate Conn,Rs,Cmd,Pram,Prams,RecordsAffectedPrivate AdoConnectionTimeout_,AdoCommandTimeout_Public Property Let LetCmdTimeout(ByVal Value)AdoCommandTimeout_ = ValueEnd PropertyPublic Property Get GetCmdTimeout()GetCmdTimeout = AdoCommandTimeout_End PropertyPublic Property Get GetRecordsAffected()GetRecordsAffected = RecordsAffectedEnd PropertyPrivate Sub Class_Initialize()AdoConnectionTimeout_ = AdoConnectionTimeoutAdoCommandTimeout_ = AdoCommandTimeoutPrams = Array()Call ReSetRecordsAffected()Call DbOpen()Set Rs = Server.CreateObject("ADODB.Recordset")    Set Cmd = Server.CreateObject("ADODB.Command")    End SubPrivate Sub Class_Terminate()Call DbClose()Call ParameterClear()End SubPrivate Sub DbOpen()On Error Resume NextApplication.LockDim connStringSet Conn = Server.CreateObject("ADODB.Connection")Conn.ConnectionTimeout = AdoConnectionTimeout_Conn.CommandTimeout = AdoCommandTimeout_''sql2000''connString = "Driver={sql server};uid=" + dbuid + ";pwd=" + dbpwd + ";database=" + dbname + ";server=" + dbIP + ";"''sql2008connString = "Driver={SQL Server Native Client 10.0};uid=" + dbuid + ";pwd=" + dbpwd + ";database=" + dbname + ";server=" + dbIP + ";"Conn.Open connStringIf Err ThenApplication.UnLock()Response.Clear()Response.Write("")Response.End()End IfApplication.UnLockEnd SubPrivate Sub DbClose()''If Conn.State = 1 Then Conn.Close()End SubPrivate Sub ReSetRecordsAffected()RecordsAffected = -1End SubPublic Sub ParameterAdd(Name_, Type_, Direction_, Size_, Value_)On Error Resume NextDim arrLengtharrLength=Ubound(Prams)+1ReDim Preserve Prams(arrLength)Set Prams(arrLength)=Cmd.CreateParameter(Name_, Type_, Direction_, Size_, Value_)If Err Then Response.Write(Err.Description)End SubPublic Sub ParameterClear()Erase PramsReDim Preserve Prams(-1)End SubPublic Function SqlExecute(Sql)On Error Resume NextCall ReSetRecordsAffected()Dim ResultResult = TrueConn.Execute Sql,RecordsAffectedIf Err Then Result = FalseSqlExecute = ResultEnd FunctionPublic Function SqlExecuteScaler(Sql)Call ReSetRecordsAffected()Dim ResultResult = NullSet Rs = Conn.Execute(Sql)If Not Rs.Eof Then Result = Rs(0)SqlExecuteScaler = ResultEnd FunctionPublic Function SqlExecuteReader(Sql)Call ReSetRecordsAffected()Set SqlExecuteReader = Conn.Execute(Sql)End FunctionPublic Function SqlExecutePageReader(Sql)Call ReSetRecordsAffected()Rs.Open Sql,Conn,3Set SqlExecutePageReader = RsEnd FunctionPublic Function PramExecute(Sql)On Error Resume NextCall ReSetRecordsAffected()Dim ResultResult = TrueCall CommandPropertySet(Sql,1)Call PramAppend()Cmd.Execute RecordsAffectedIf Err Then Result = FalsePramExecute = ResultEnd FunctionPublic Function PramExecuteScaler(Sql)Call ReSetRecordsAffected()Dim ResultResult = NullCall CommandPropertySet(Sql,1)Call PramAppend()Set Rs=Cmd.Execute()If Not Rs.Eof Then Result = Rs(0)PramExecuteScaler = ResultEnd FunctionPublic Function PramExecuteReader(Sql)Call ReSetRecordsAffected()Call CommandPropertySet(Sql,1)Call PramAppend()Set PramExecuteReader=Cmd.Execute()End FunctionPublic Function PramExecutePageReader(Sql)Call ReSetRecordsAffected()Call CommandPropertySet(Sql,1)Call PramAppend()Call RecordsetPagePropertySet()Set PramExecutePageReader=RsEnd FunctionPublic Function ProcExecute(ProcName)Call ReSetRecordsAffected()Call CommandPropertySet(ProcName,4)Cmd.Parameters.append Cmd.CreateParameter("@return",3,4)Call PramAppend()Cmd.Execute()ProcExecute = Cmd(0)End FunctionPublic Function ProcExecuteScaler(ProcName)Call ReSetRecordsAffected()Dim ResultResult = NullCall CommandPropertySet(ProcName,4)Call PramAppend()Set Rs=Cmd.Execute()If Not Rs.Eof Then Result = Rs(0)ProcExecuteScaler = ResultEnd FunctionPublic Function ProcExecuteReader(ProcName)Call ReSetRecordsAffected()Call CommandPropertySet(ProcName,4)Call PramAppend()Set ProcExecuteReader=Cmd.Execute()End FunctionPublic Function ProcExecutePageReader(ProcName)Call ReSetRecordsAffected()Call CommandPropertySet(ProcName,4)Call PramAppend()Call RecordsetPagePropertySet()Set ProcExecutePageReader=RsEnd FunctionPrivate Sub RecordsetPagePropertySet()''返回一個帶Cursor的記錄集With Rs.CursorLocation=3'adUseClient.CursorType=0'0=adOpenForwardOnly.LockType=1'1=adLockReadOnly
            .Open Cmd.ActiveConnection = NothingEnd WithEnd SubPrivate Sub CommandPropertySet(CommandText_,CommandType_)With Cmd.CommandTimeout   = AdoCommandTimeout_.ActiveConnection = Conn.CommandText      = CommandText_.CommandType      = CommandType_.Prepared         = trueEnd WithEnd SubPrivate Sub PramAppend()For Each Pram in PramsCmd.Parameters.append PramNextEnd SubPublic Function GetOutPut(HaveRecordset)Dim OutPut,arrLengthOutPut = Array()If HaveRecordset Then Rs.Close()For Each Pram in Cmd.Parameters''Response.Write Pram.name &"="& trim(Pram) &"
"
If Pram.Direction=2 Or Pram.Direction=3 ThenarrLength=Ubound(OutPut)+1ReDim Preserve OutPut(arrLength)OutPut(arrLength)=PramEnd IfNextIf HaveRecordset Then Rs.Open()GetOutPut = OutPutEnd FunctionEnd Class %>

 

更多相关:

  • 转自:http://helloaq.iteye.com/blog/221614 exec 和 call 执行一个procedure时,   exec是sqlplus的命令,只能在sqlplus中使用。 call是sql命令,任何工具都可以使用 转载于:https://www.cnblogs.com/zerocc/archive/...

  • Python是一种计算机程序设计语言,它是一种动态的、面向对象的脚本语言。它是一种跨平台的,可以运行在 Windows,Mac和 Linux/Unix系统上。在日常使用中需要对大量数据进行数据分析,那么就必然用到数据库,我们常用的数据库有 SQL Server , MySQL , Oracle , DB2 , SQLite ,Hive...

  • 在VS下用C语言连接SQLServer2008 原文:在VS下用C语言连接SQLServer2008 step1:启动SQLSERVER服务 step2:打建立数据库test,在test库中建立test表(a varchar(200),b varchar(200))  step3:建立系统DSN,开始菜单 ->运行 ->o...

  • 打开SQL Server Configuration Manager,在SQL server配置管理器展开SQL server 2005网络配置-->SQLEXPRESS 的协议-->双击TCP/IP协议-->ip地址将1433端口启用,重启下MSSQL服务才能生效,示例图: 重启下MSSQL服务才能生效 转载于:https:/...

  • 一.ITL(Interested Transaction List):   ITL(Interested Transaction List)是Oracle数据块内部的一个组成部分,位于数据块头(block header),itl由xid,uba,flag,lck和scn/fsc组成,用来记录该块所有发生的事务,一个itl可以看作是一条...

  • 转自http://blog.chinaunix.net/space.php?uid=16981447&do=blog&cuid=430716做了简单的格式整理,加入了一点点原创的东西。Oracle9i引入了MERGE命令,你能够在一个SQL语句中对一个表同时执行inserts和updates操作. MERGE命令从一个或多个数据源中选...