连接数据库

上一篇 / 下一篇  2007-04-16 21:55:06 / 个人分类:QTP

dim cnn,rst,strcnn,strsql
set cnn = createobject("adodb.connection")
set rst = createobject("adodb.recordset")
strcnn = "数据库连接字符串"
cnn.open = strcnn
strsql = "select * from table_a"
rst.open strsql,strcnn,2,2//参数为1,3时可用RECORDCOUNT取到记录总数,为2时返回-1
msgbox rst("abc") //取查询到的结果,字段名为abc的值,或第2列的值,第一列的index为0
msgbox rst(2)
rst.close
cnn.close
set rst = nothing
set cnn = nothing

Dim res,cmd,sql
Set res = createobject("adodb.recordset")
Set cmd = createobject("adodb.command")cmd.activeconnection="数据库连接字符串"
cmd.CommandType = 1
sql = "select max(order_number) as a from orders"
cmd.CommandText = sqlSet
res = cmd.execute()
Set res = nothingSet
cmd.ActiveConnection = nothing
Set cmd = nothing

数据库连接字符串可以建立UDL文件来获得


TAG: QTP

薛双的个人空间 引用 删除 薛双   /   2011-09-02 14:51:53
 

评分:0

我来说两句

我的栏目

日历

« 2024-04-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 10950
  • 日志数: 17
  • 文件数: 1
  • 建立时间: 2007-01-27
  • 更新时间: 2007-10-24

RSS订阅

Open Toolbar