51Testing软件测试论坛

标题: qtp求教 [打印本页]

作者: wdlcoke    时间: 2010-8-6 10:45
标题: qtp求教
***qtp咋样从数据库里取值???
作者: TIB    时间: 2010-8-6 14:03
要看什么数据库,一般通过ADO可连接,下面是SQLServer的例子:
  1. Dim Conn
  2. Dim Rst
  3. Dim str_Link_DBSource
  4. str_Link_DBSource="Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=TEST"

  5. Set Conn=CreateObject("ADODB.Connection")
  6. Conn.Open str_Link_DBSource

  7. Set Rst=CreateObject("ADODB.Recordset")
  8. Rst.Open "select * from Orders",Conn,2,2
  9. Rst.MoveFirst
  10. Do While Rst.Eof<>true
  11.       Print Rst.Fields(0) & " " & Rst.Fields(1) & " " & Rst.Fields(2)
  12.       Rst.MoveNext
  13. Loop

  14. Rst.Close
  15. Conn.Close
  16. Set Rst=Nothing
  17. Set Conn=Nothing
复制代码





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2