什么是线性回归:一个VB奇怪的问题?
来源:百度文库 编辑:高校问答 时间:2024/04/30 05:01:32
各位高手:以下是我的一部分代码,现在有一个很奇怪的问题就是有时好像会出现一种死循坏。
我这程序是想从一个数据库里把数据A转到另一个数据库B,采用读一条然后向另一个写一条,下面的代码多数情况下是没问题的,但有时在数据库A里只有几条数据但是转到数据库B时却出现了上十万条,我想可能是出现了死循坏但又找不出原因。请帮帮我!谢谢!
Dim erA, erB As String
Dim strSQLN As String '更新rvfflag 为 Y
Dim comN As New ADODB.Command
strSQLI = ""
strSQL = ""
strSQLN = ""
erA = ""
erB = ""
'**************************************
On Error GoTo err5 '判断查询是否成功
strSQLI = "select pmm09,rvf02,rvf03,rvf04,rvf01,rvfdate from rvf_file,pmm_file where rvf_file.rvf01 =pmm_file.pmm01 and rvfflag='N'"
connI.CursorLocation = adUseClient
connI.Open strConnO
rsI.Open strSQLI, connI, adOpenKeyset, adLockPessimistic
If Not rsI.EOF Then
Do While Not rsI.EOF
'*** 更新已转的记录,改 N 为 Y 这里是标识已转了的就不用再转了 ***************
On Error GoTo err2
strSQLN = "update rvf_file set rvfflag='Y' where rvf01='" & rsI("rvf01") & "' and rvf02='" & rsI("rvf02") & "' and rvfdate='" & rsI("rvfdate") & "'"
comN.ActiveConnection = connI
comN.CommandText = strSQLN
comN.Execute
'************************************************
On Error GoTo err1
strSQL = "insert into ecImpPODelivQty(SendID,RecvID,E_FROM,E_DATE,E_TIME,T_COMP) values('PGLL','" & rsI("pmm09") & "'," & rsI("rvf01") & " ','" & Format(Date, "yyyymmdd") & "','" & Format(Time, "hhmmss") & Right(GetTickCount, 3) & "','POS')"
conn.CursorLocation = adUseClient
conn.Open strconn
com.ActiveConnection = conn
com.CommandText = strSQL
com.Execute
conn.Close
Set conn = Nothing
'*********************************************
rsI.MoveNext
Loop
Else
'没记录就退出
rsI.Close
Set rsI = Nothing
connI.Close
Set connI = Nothing
Exit Sub
End If
rsI.Close
Set rsI = Nothing
connI.Close
Set connI = Nothing
'***************************************** 以下是想把出错时的SQL语句输出到TXT 里。
If erA <> "" Or erB <> "" Then
Open "E:\ECerror\POSJ" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & ".txt" For Output As #1
Print #1, erA & Chr(13) & erB
Close #1
End If
Exit Sub
err1:
erA = erA & Chr(13) & strSQL
Resume Next
Exit Sub
err2:
erB = erB & Chr(13) & strSQLN
Resume Next
err5:
Open "E:\POSJ" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & ".txt" For Output As #1
Print #1, "数据连接错误!"
Close #1
widebright 你的建议不错.你能告诉我怎么改进会更好吗?比如自己如何去自己写错误处理代码?谢谢!
我这程序是想从一个数据库里把数据A转到另一个数据库B,采用读一条然后向另一个写一条,下面的代码多数情况下是没问题的,但有时在数据库A里只有几条数据但是转到数据库B时却出现了上十万条,我想可能是出现了死循坏但又找不出原因。请帮帮我!谢谢!
Dim erA, erB As String
Dim strSQLN As String '更新rvfflag 为 Y
Dim comN As New ADODB.Command
strSQLI = ""
strSQL = ""
strSQLN = ""
erA = ""
erB = ""
'**************************************
On Error GoTo err5 '判断查询是否成功
strSQLI = "select pmm09,rvf02,rvf03,rvf04,rvf01,rvfdate from rvf_file,pmm_file where rvf_file.rvf01 =pmm_file.pmm01 and rvfflag='N'"
connI.CursorLocation = adUseClient
connI.Open strConnO
rsI.Open strSQLI, connI, adOpenKeyset, adLockPessimistic
If Not rsI.EOF Then
Do While Not rsI.EOF
'*** 更新已转的记录,改 N 为 Y 这里是标识已转了的就不用再转了 ***************
On Error GoTo err2
strSQLN = "update rvf_file set rvfflag='Y' where rvf01='" & rsI("rvf01") & "' and rvf02='" & rsI("rvf02") & "' and rvfdate='" & rsI("rvfdate") & "'"
comN.ActiveConnection = connI
comN.CommandText = strSQLN
comN.Execute
'************************************************
On Error GoTo err1
strSQL = "insert into ecImpPODelivQty(SendID,RecvID,E_FROM,E_DATE,E_TIME,T_COMP) values('PGLL','" & rsI("pmm09") & "'," & rsI("rvf01") & " ','" & Format(Date, "yyyymmdd") & "','" & Format(Time, "hhmmss") & Right(GetTickCount, 3) & "','POS')"
conn.CursorLocation = adUseClient
conn.Open strconn
com.ActiveConnection = conn
com.CommandText = strSQL
com.Execute
conn.Close
Set conn = Nothing
'*********************************************
rsI.MoveNext
Loop
Else
'没记录就退出
rsI.Close
Set rsI = Nothing
connI.Close
Set connI = Nothing
Exit Sub
End If
rsI.Close
Set rsI = Nothing
connI.Close
Set connI = Nothing
'***************************************** 以下是想把出错时的SQL语句输出到TXT 里。
If erA <> "" Or erB <> "" Then
Open "E:\ECerror\POSJ" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & ".txt" For Output As #1
Print #1, erA & Chr(13) & erB
Close #1
End If
Exit Sub
err1:
erA = erA & Chr(13) & strSQL
Resume Next
Exit Sub
err2:
erB = erB & Chr(13) & strSQLN
Resume Next
err5:
Open "E:\POSJ" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & ".txt" For Output As #1
Print #1, "数据连接错误!"
Close #1
widebright 你的建议不错.你能告诉我怎么改进会更好吗?比如自己如何去自己写错误处理代码?谢谢!
整理一下你的异常处理语句吧。可能是和使用Resume Next 语句有关。 有时出错了但数据库游标有不移到下一条记录,又在Resume Next 后回到原来的地方继续执行了。
你的 一个函数里 on error还使用了几层嵌套感觉很乱,
我的观点是能不用异常处理就不用,可以自己写错误处理代码的。
天哪……你多分几个函数吧……