目錄1 概述 1
1.1qtp學習筆記 1
2 運算元據庫 1
2.1開啟資料庫的一般操作 1
2.2在recordset元件中,常用的屬性和方法有 2
3 function 2
3.1連線mysql資料庫,讀取後儲存到指定檔案 2
3.2連線mysql資料庫,儲存格式為hh:mm:ss的資料 6
qtp連線讀取mysql的資料
set conn=createobject("")'建立資料庫例項
connectionstring="driver=;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev;option=3;stmt=set names gbk"
connectionstring'連線資料庫
set str=createobject("")'建立資料集例項
sql =select * from v_epg_item
sql,conn,1,1 '1,1表示唯讀;1,3表示插入資料;2,3表示修改資料
'釋放資源
set str = nothing
set conn = nothing
用vbs取mysql中文出現亂碼
sconnection = "driver=; server=localhost; database=code52_lib; uid=root;password=123456; option=3;stmt=set names 'gbk'"
recordset物件的字段數。
str(i).name: 第i個字段的名稱,i為0至
str(i): 第i個字段的資料,i為0至
str("欄位名"): 指定欄位的資料。
游標中的資料記錄總數。
是否最後一條記錄。
指向第一條記錄。
指向最後一條記錄。
指向上一條記錄。
指向下一條記錄。
將資料放入陣列中。
的resultset或connection的屬性個數。
的resultset或connection的名稱。
ado的resultset或connection的值。
關閉連線。
呼叫方法
const connstring = "driver=;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev;option=3;stmt=set names gbk"
'sqlstring = "select * from e_fetch_item where id between 90000 and 94000"
sqlstring = "select * from e_fetch_item where id = 92601"
qtp_openmysql connstring, sqlstring, "d:\temp1","d:\temp1\mysql_"
實現函式
' 函式說明:開啟資料庫
' 引數說明:
1)connstring:配置資料庫的引數,如
const connectionstring="dsn=jhk_database;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev"
'const connectionstring="driver=;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev;stmt=set names gbk"
2)sqlstring:查詢資料庫的語句,如
sql ="select * from e_fetch_item where id < '9338'"
3)mysqldata_path:儲存查詢資料庫的內容的檔案路徑
4)mysqldata_pathname:儲存查詢資料庫的內容的檔案路徑+名稱
' 呼叫方法:
const connstring = "driver=;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev;stmt=set names gbk"
sqlstring = "select * from e_fetch_item where id < '9338'"
qtp_openmysql connstring, sqlstring, "d:\mysql_"
function qtp_openmysql(connstring,sqlstring,mysqldata_path,mysqldata_pathname)
'qtp_createexcel "d:\temp1","d:\temp1\mysql_" '建立mysql_檔案,注意此處呼叫了qtp_createexcel函式
qtp_createexcel mysqldata_path,mysqldata_pathname '建立mysql_檔案,注意此處呼叫了qtp_createexcel函式
'開啟mysql_pat**件
set excelapp=createobject("")
set excelbook=
set excelsheet="sheet1")
資料庫操作
dim conn,str,row,col,numcolumn
set conn=createobject("")'建立資料庫例項
'const connectionstring="driver=;database=jhk;pwd=123456;port=3306;server=192.168.10.
44;uid=jhk_dev;option=3;stmt=set names gbk"
connectionstring=connstring
connectionstring
if <>0 then
micpass,"testing","連線資料庫成功"
else
micfail,"testing","連線資料庫失敗"
end if
set str=createobject("")'建立資料集例項
查詢資料庫
sql =sqlstring
'開啟乙個資料集
sql,conn,1,1 '1,1表示唯讀;1,3表示插入資料;2,3表示修改資料
'使游標指向第乙個記錄
numcolumn =
for headline = 1 to numcolumn step 1
= str(headline-1).name
' = vbblue
next
'"g:h").numberformat設定d列的日期格式為yyyy-m-d
"d:d").numberformat = "yyyy-m-d" '設定d列的日期格式為yyyy-m-d
"e:f").numberformat = "hh:mm:ss" '設定e到f列的時間格式為hh:mm:ss
"i:i").numberformat = "yyyy-m-d hh:mm:ss" '設定i列的時間格式為yyyy-m-d hh:mm:ss
"n:n").numberformat = "yyyy-m-d hh:mm:ss" '設定n列的時間格式為yyyy-m-d hh:mm:ss
"a1:n1"). = 16'設定單元格底色,"b1:e1"為行列數
"a1:n1"). = true' 設定單元格的字型為粗體
"a:n").wraptext = true '設定單元格a到n列為自動換行
"g:h").columnwidth = 30 '設定第h列寬為30
'"a:n"). = "arial" '設定顯示區域的字型型別
'"a:n"). = 10 '設定顯示區域的字型大小
'"a2:e1"). = 50 '設定顯示區域的字型的顏色
"a:n").horizontalalignment = 2 '4右邊對齊; 3 居中; 2 左邊對齊;
'"a2:a2").borders(1).linestyle = 1'設定單元格左邊界線 1為有界,0為無界
'"a2:a2").borders(2).linestyle = 1 '設定單元格右邊界線 1為有界,0為無界
'"a2:a2").borders(3).linestyle = 1 '設定單元格上邊界線 1為有界,0為無界
'"a2:a2").borders(4).linestyle = 1' 設定單元格下邊界線 1為有界,0為無界
'"a2:b4").merge '合併單元格
row = 2
while not
'msgbox "username")
for col=0 to '表示字段個數
if ( (str(col).name = "start_time" or str(col).name = "end_time") and (str(col).
value <> "null") )then
if (cdate(str(col).value) <> date) then
'處理時間帶當天日期
elseif (cdate(str(col).value) = date) then
"00:00:00")'處理時間為00:00:00的時間
end if
else
end if
'sum=sum & str(i) & " " '把整個記錄顯示出來
next
'print sum & vbcrlf'列印所有查詢的記錄
'使游標進入下乙個
row = row + 1
wend
'關閉資料集例項
set str=nothing
'關閉資料庫例項
set conn=nothing
on error resume next
set excelbook=nothing
set excelapp=nothing
end function
在用qtp連線mysql資料庫,查詢資料並儲存到指定excel時,遇到了如下的問題:
1, 當mysql裡的資料為17:56:00這樣的時間格式時,因為qtp讀到的mysql資料會自動加今天的日期,所以儲存到excel會變為2013-8-12 17:
56:00(2013-8-12為當前日期),而我僅想儲存為hh:mm:
ss格式
2, 為解決問題1,採用right(str(col),8)方式來擷取右邊後8位數存,但遇到另乙個問題,當時間為」07:56:00」,會儲存為」 7:56:00」
3, 當時間為00:00:00,寫到excel表裡會只寫如當天日期,如2013-8-12,而無時間
問題1解決:判斷是否為時間列,如果是則使用right函式擷取
問題2解決:在存到excel之前,使用cdate函式格式化為日期
實現函式如下:
for col=0 to '表示字段個數
if ( (str(col).name = "start_time" or str(col).name = "end_time") and (str(col).
value <> "null") )then
if (cdate(str(col).value) <> date) then
elseif (cdate(str(col).value) = date) then
"00:00:00")
end if
else
end if
問題3解決:判斷當前的值僅為當天日期,則改為00:00:00
if(cdate(str(col).value)=date)then
"00:00:00")
end if
8255卡控制X Y TABLE之連線程式
實驗四一 實驗題目 1.鏈結馬達向右前進三秒 時速約3mm sec 再向左後退三秒 時速約 3mm sec 後停止 2.鏈結馬達向右前進一秒 時速約3mm sec 停止二秒,再向左後退三秒 時 速約3mm sec 後停止 3.鏈結馬達向左前進二秒 時速約3mm sec 再向右後退四秒 時速約 3mm...
本地連線已連線有傳送無接收
在日常的網路維護中,常常出現 本地連線 有傳送無接收,這個故障曾經讓我傷透腦筋,現在也沒有乙個正確的解決方案,而下面列舉的是我在處理這些故障過程中,所遇到的各類問題以及應付措施。1.禁用網絡卡,然後重新啟用,重新啟動電腦 插拔網線,看情況是否改善。備註 用這個辦法我也解決了好多這類問題,簡單不費時間...
五下科學期末複習大全之四連線題
1 蠟燭 橡皮 馬鈴薯 回形針小石頭 2 潛艇擠完壓載艙裡的水 馬鈴薯放到水中下沉 馬鈴薯放到濃鹽水中 塑料塊放到食用油中上浮 軟木塞放在水中 軟木塞放在食用油中 3 在 地球公轉 的模擬實驗中,不同的材料或動作各代表什麼?用線連線起來。操場上畫乙個圓圈地球圍繞太陽公轉 圓圈中心的紅色圓紙片太陽 遠...