|
不需要吧,这里有发过几个函数的http://bbs.51testing.com/thread-374191-1-1.html
不过这种用法参数较多,比较繁琐,最好把tns做在配置文件中去读
- '******************************************************************************************
- '设计说明: 从数据库中抓取指定表和列的数据,依赖ORAOLEDB组件的正常使用,不用创建数据源,不用配置连接串
- '程序输入:
- ' 1. DBUserName -- 数据库用户名
- ' 2. DBHostAddress -- 数据库主机的域名或IP
- ' 3. DBServerPort -- 数据库主机的端口
- ' 4. DBSid -- 数据库实例SID
- ' 5. DBPassWord -- 数据库用户的密码
- ' 6. sqlText -- 要执行的sql语句
- ' 7. tableColumn -- 要抓取的字段
- '程序输出: 要抓取的字段
- '设计人员: 刘毅(LIUYI)
- '设计时间: 2009-09-26
- '调用举例: MsgBox FetchDBDataOle("select * from plan","plan_code","A","10.31.10.105","1555","B","C")
- '******************************************************************************************
- Public Function FetchDBData(DBUserName,DBHostAddress,DBServerPort,DBSid,DBPassWord,sqlText,tableColumn)
- On Error Resume Next
- Set DBRec=createobject("adodb.recordset")
- Set DBCon=createobject("adodb.Connection")
-
- DBCon.ConnectionString="Provider=""OraOLEDB.Oracle"";User ID="&_
- DBUserName &";Data Source=""(description =(address = (protocol = tcp)(host = "&_
- DBHostAddress &")(port = "&_
- DBServerPort&"))(connect_data =(sid = "&_
- DBSid&")))"";Password="&_
- DBPassWord&""
-
- DBCon.Open
- DBRec.Open sqlText,DBCon
- FetchDBData = DBRec.Fields(tableColumn)
- DBCon.Close
- Set DBRec = Nothing
- Set DBCon = Nothing
- ErrorHandle "FetchDBData"
- End Function
- '******************************************************************************************
- '设计说明: 从数据库中抓取指定表和列的数据,基于MSDAORA对象的使用,不用创建数据源,不用配置连接串
- '程序输入:
- ' 1. DBUserName -- 数据库用户名
- ' 2. DBHostAddress -- 数据库主机的域名或IP
- ' 3. DBServerPort -- 数据库主机的端口
- ' 4. DBSid -- 数据库实例SID
- ' 5. DBPassWord -- 数据库用户的密码
- ' 6. sqlText -- 要执行的sql语句
- ' 7. tableColumn -- 要抓取的字段
- '程序输出: 要抓取的字段
- '设计人员: 刘毅(LIUYI)
- '设计时间: 2009-09-26
- '调用举例: MsgBox FetchDBData("select * from plan","plan_code","A","10.31.10.105","1555","B","C")
- '******************************************************************************************
- Public Function FetchDBDataMSDAORA(DBUserName,DBHostAddress,DBServerPort,DBSid,DBPassWord,sqlText,tableColumn)
- On Error Resume Next
- Set DBCon = CreateObject("ADODB.Connection")
- Set DBRec = CreateObject("ADODB.RecordSet")
-
- DBCon.Open = "Provider=""MSDAORA.Oracle"";User ID="&_
- DBUserName&";Data Source=""(description =(address = (protocol = tcp)(host = "&_
- DBHostAddress &")(port = "&_
- DBServerPort&"))(connect_data =(sid = "&_
- DBSid&")))"";Password="&_
- DBPassWord&""
-
- DBRec.OPEN sqlText,DBCon
- FetchDBDataMSDAORA = DBRec.fields(tableColumn)
- DBCon.close
- Set DBCon =Nothing
- Set DBRec = Nothing
- ErrorHandle "FetchDBDataMSDAORA"
- End Function
- '******************************************************************************************
- '设计说明: 按照传入SQL修改数据库的值,依赖ORAOLEDB组件的正常使用,不用创建数据源,不用配置连接串
- '程序输入:
- ' 1. DBUserName -- 数据库用户名
- ' 2. DBHostAddress -- 数据库主机的域名或IP
- ' 3. DBServerPort -- 数据库主机的端口
- ' 4. DBSid -- 数据库实例SID
- ' 5. DBPassWord -- 数据库用户的密码
- ' 6. sqlText -- 要执行的sql语句
- '程序输出: 无
- '设计人员: 刘毅(LIUYI)
- '设计时间: 2009-09-26
- '调用举例: Call ModifyDBDataOle("A","10.31.10.105","1555","B","C","update Test set colNum = 'A' where colNum = 'B'")
- '******************************************************************************************
- Public Function ModifyDBData(DBUserName,DBHostAddress,DBServerPort,DBSid,DBPassWord,sqlText)
- On Error Resume Next
- Set DBRec=createobject("adodb.recordset")
- Set DBCom=createobject("adodb.command")
-
- DBCom.activeconnection="Provider=""OraOLEDB.Oracle"";User ID="&_
- DBUserName&";Data Source=""(description =(address = (protocol = tcp)(host = "&_
- DBHostAddress&")(port = "&_
- DBServerPort&"))(connect_data =(sid = "&_
- DBSid&")))"";Password="&_
- DBPassWord&""
-
- DBCom.CommandType = 1
- DBCom.CommandText = sqlText
- Set DBRec = DBCom.Execute()
- DBCom.CommandText = "commit"
- Set DBRec = DBCom.Execute()
- Set DBRec = Nothing
- Set DBCom = Nothing
- ModifyDBData = ErrorHandle("ModifyDBData")
- End Function
- '******************************************************************************************
- '设计说明: 按照传入SQL修改数据库的值,基于MSDAORA对象的使用,不用创建数据源,不用配置连接串
- '程序输入:
- ' 1. DBUserName -- 数据库用户名
- ' 2. DBHostAddress -- 数据库主机的域名或IP
- ' 3. DBServerPort -- 数据库主机的端口
- ' 4. DBSid -- 数据库实例SID
- ' 5. DBPassWord -- 数据库用户的密码
- ' 6. sqlText -- 要执行的sql语句
- '程序输出: 无
- '设计人员: 刘毅(LIUYI)
- '设计时间: 2009-09-26
- '调用举例: Call ModifyDBData("A","10.31.10.105","1555","B","C","update Test set colNum = 'A' where colNum = 'B'")
- '******************************************************************************************
- Public Function ModifyDBDataMSDAORA(DBUserName,DBHostAddress,DBServerPort,DBSid,DBPassWord,sqlText)
- On Error Resume Next
- Set DBCon = CreateObject("ADODB.Connection")
- Set DBRec = CreateObject("ADODB.RecordSet")
-
- DBCon.Open = "Provider=""MSDAORA.Oracle"";User ID="&_
- DBUserName&";Data Source=""(description =(address = (protocol = tcp)(host = "&_
- DBHostAddress &")(port = "&_
- DBServerPort&"))(connect_data =(sid = "&_
- DBSid&")))"";Password="&_
- DBPassWord&""
-
- DBRec.OPEN sqlText,DBCon
- DBRec.OPEN "commit",DBCon
- DBCon.Close
- Set DBCon =Nothing
- Set DBRec = Nothing
- ModifyDBDataMSDAORA = ErrorHandle("ModifyDBDataMSDAORA")
- End Function
复制代码 |
|