在生前一定要做完想做的事!

创建数据源

上一篇 / 下一篇  2008-04-27 20:43:24 / 个人分类:qtp

在控制面板的管理工具中 创建数据源

选择system dsn tab

点add 操作 选择microsoft odbc for oracle

输入数据源的名字.这个要跟脚本里的参数名一致(下面例子里面的forum)

topsql = "select count(*) from tbf_thread where forum_id = '85' and thread_type = '2'"
topcount = getone1(forum,topsql)

脚本里怎么连接数据库

Function OpenConnection1 (dataSource)
 Set cnn = CreateObject("ADODB.Connection")
  cnn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=true;User ID=id;Password=pwd;Data Source=" &dataSource
    cnn.Open
 Set OpenConnection1 = cnn
End Function

从数据库中获取数据

Function GetOne1(datasource,sql)
 cnn = OpenConnection1(dataSource)
 Set rs = CreateObject("ADODB.RecordSet")
 rs.open sql,cnn,1,1
 GetOne1 = null
 If Not rs.eof Then
  GetOne1 = rs.Fields(0).value
  'msgbox GetOne
 End If
' rs.close
 Set rs = nothing
End Function

脚本中引用这个函数

sql = "select count(*) from 表 where 条件"
topcount = getone1(跟数据源名字一样,topsql)


TAG: 创建数据源 qtp

 

评分:0

我来说两句

日历

« 2024-04-05  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 10246
  • 日志数: 10
  • 建立时间: 2008-02-18
  • 更新时间: 2009-10-26

RSS订阅

Open Toolbar