我現在已經實作了將資料匯入到dw中,而且只有兩列的資料表也可以更新進sql資料庫中,但是一般sql資料庫中的表都有好多列,我在dw中選擇一個表的某幾列或者兩個表的某幾列,這樣匯入sql資料庫的時候就會出錯,請教各位大俠有沒有誰有個例子能參考下?
附上我的匯入代碼:
dw_1.settransobject(sqlca)
string ls_null
SetNull(ls_null)
dw_1.ImportFile(ls_null)
//這個是匯入的csv資料表
更新代碼:
if dw_1.update() = 1 then
commit;
messagebox("","OK")
else
rollback;
messagebox("","failure")
end if
dw_1.settransobject(sqlca)
dw_1.retrieve()
如果需要逐條更新的話,有具體的代碼嗎?小弟是超級菜鳥。
uj5u.com熱心網友回復:
從資料視窗中用回圈,把所有的列放進每一個變數中,然后用insert或update陳述句.大致為:
假設兩個列
string c1 , c2
long i , j
for i = 1 to dw_1.rowcount()
c1 = dw_1.getitemstring(i , "c1")
c1 = dw_1.getitemstring(i , "c2")
select count(1) into :j from tb where c1 = :c1
if j = 1 then//假設c1為主鍵,表示存在,只有一個.
update tb set c2 = :c2 where c1 = :c1
else
insert into tb(c1,c2) values(:c1 , :c2)
end for
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/92195.html
標籤:腳本語言
上一篇:為什么不能備份
下一篇:列印中的問題
