天天看點

QTP連結到PostgreSQL資料庫

'連結資料庫

set conn=CreateObject("ADODB.Connection")

ConnectionString="DSN=PostgreSQL30;DATABASE=資料庫名(比如aap);SERVER=伺服器ip位址(比如172.168.1.2);PORT=端口号(比如:5432);UID=postgres;PWD=postgres;"

conn.Open   ConnectionString

 這裡注意下,請先檢視Administrative Tools/Data Sources (ODBC)中的system DSN中是否有PostgreSQL30這個服務,如果沒有需要添加上,添加之前需要安裝下PostgreSQL30

另外,如果你不能夠确定你上面的連結語句是否正确,可以通過插入資料庫檢查點的時候,選擇第二項,即【Specify SQL statement manual】通過選擇Specify SQL statement manual選項,然後選擇你指定的資料源,就會得到一個連接配接字元串,你可以将這個連結字元串copy過來

''檢視連接配接是否已建立

'If conn.State=0 Then

' msgbox"failed"

' else

' msgbox"pass"

'End If

'建立空的記錄集

Set rs=CreateObject("ADODB.RecordSet")

'設定SQL語句

sql="select cust_sku_no,description,cust_mfg_no,dept_no,asia_mgr,usa_mgr, usa_dir   from cp_md_product where cust_sku_no=6300002"

'打開記錄集

rs.open sql,conn

rs.MoveFirst

'循環取數,資料表列名為aaa/bbb/ccc/ddd/eee

 'Do until rs.eof

 A = rs("cust_sku_no").value

...

rs.next

loop