datareader循环嵌套

liubaohuazy 2007-07-13 06:22:42
两个datareader循环嵌套,内层每次循环后结束连接,关闭datareader,但是下次循环的时候当执行到datareader=command.executeReader是就死了。没有任何提示。
到底为什么呢?
...全文
271 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
liubaohuazy 2007-07-16
  • 打赏
  • 举报
回复
wenh7788 2007-07-16
  • 打赏
  • 举报
回复
就是看看代码
liubaohuazy 2007-07-16
  • 打赏
  • 举报
回复

'有可能是多个财务ID
CMD_CW.Connection = CN.get_c(Str_Connection)
CMD_CW.CommandText = "select * from cwb where id in(select cwid from cwb_fz where xmid like'" & XMID.Trim & "')"
REA_CW = CMD_CW.ExecuteReader
Dim i As Integer
i = 0
Dim C(i) As CW

While REA_CW.Read
ReDim Preserve C(i)
C(i) = New CW '保存财务记录的值
C(i).set_values(REA_CW.Item("hymc").ToString.Trim, REA_CW.Item("dzgs").ToString.Trim, _
REA_CW.Item("lxdh").ToString.Trim, "", CType(REA_CW.Item("bcss"), Decimal), REA_CW.Item("fkfs").ToString.Trim, _
CType(REA_CW.Item("qz"), Integer), REA_CW.Item("pzh").ToString.Trim, CType(REA_CW.Item("dkrq"), Date), _
REA_CW.Item("ywy"), REA_CW.Item("zh"), CType(REA_CW.Item("id"), Integer))
i += 1

Dim CMD_FZ_CX As New SqlCommand
Dim REA_CX As SqlDataReader
Dim CN_FZ As New CN_ZW
CMD_FZ_CX.Connection = CN_FZ.get_c(Str_Connection)
CMD_FZ_CX.CommandText = "select * from CWB_FZ where CWID=" & Trim(REA_CW.Item("id"))
REA_CX = CMD_FZ_CX.ExecuteReader

SL = DE_CW.DEL_ADD_CW(CON_CW, myTrans_CW, CType(REA_CW.Item("id"), Integer), REA_CX)

CMD_FZ_CX.Dispose()
CMD_FZ_CX = Nothing
CN_FZ.lost_c()
CN_FZ = Nothing
Public Function DEL_ADD_CW(ByRef CON_DE As SqlConnection, ByRef myTrans_DE As SqlTransaction, ByVal ID_DE As Integer, ByVal REA_CX As SqlDataReader) As String

'此函数用于删除财务


'检索------------------------------------------

'删除数量的变量

Dim XH_SL As Integer
While REA_CX.Read
'0财务id 1 项目id 2 bh 3 jdm 4 hymc 5 je (6)是表名 7 rq 8 id
If Trim(REA_CX.Item(6)) = "ZWB" Then
'删除展位表中相应的纪录的金额
Dim ZW_DE As New ZW
XH_SL += ZW_DE.DEL_ZSS(CON_DE, myTrans_DE, Trim(REA_CX.Item(2)), Trim(REA_CX.Item(4)), Trim(REA_CX.Item(1)), Trim(REA_CX.Item(5)))
ElseIf Trim(REA_CX.Item(6)) = "HWB" Then
Dim HW_DE As New HW
XH_SL += HW_DE.DEL_ZSS(CON_DE, myTrans_DE, Trim(REA_CX.Item(1)), Trim(REA_CX.Item(4)), Trim(REA_CX.Item(2)), Trim(REA_CX.Item(5)))
ElseIf Trim(REA_CX.Item(6)) = "GGB" Then
Dim GG_DE As New GG
XH_SL += GG_DE.DEL_ZSS(CON_DE, myTrans_DE, Trim(REA_CX.Item(2)), Trim(REA_CX.Item(4)), Trim(REA_CX.Item(1)), Trim(REA_CX.Item(5)))
ElseIf Trim(REA_CX.Item(6)) = "JDB" Then
Dim JD_DE As New JD
XH_SL += JD_DE.DEL_ZSS(CON_DE, myTrans_DE, Trim(REA_CX.Item(2)), Trim(REA_CX.Item(3)), Trim(REA_CX.Item(4)), Trim(REA_CX.Item(1)), _
Trim(REA_CX.Item(5)))
ElseIf Trim(REA_CX.Item(6)) = "HMD" Then
Dim HMD_DE As New HMD
XH_SL += HMD_DE.DEL_ZSS(CON_DE, myTrans_DE, Trim(REA_CX.Item(1)), Trim(REA_CX.Item(2)), Trim(REA_CX.Item(4)), Trim(REA_CX.Item(5)), ID_DE)
Else
MsgBox("表名错误,请联系管理员,数据库中的数据产生了严重的错误!可能是人为更改了数据库中的字段值!", 32, "提示")
DEL_ADD_CW = "表名错误,请联系管理员,数据库中的数据产生了严重的错误!"
Exit Function
End If

End While

'------------------------------------end
Dim CMD_DE_CW As New SqlCommand
Dim DE_SL As Integer

Dim CMD_FZ As New SqlCommand
Dim FZ_SL As Integer
Try


CMD_DE_CW.Connection = CON_DE
CMD_DE_CW.Transaction = myTrans_DE
CMD_DE_CW.CommandText = "delete from CWB where id=" & ID_DE
DE_SL = CMD_DE_CW.ExecuteNonQuery

CMD_FZ.Connection = CON_DE
CMD_FZ.Transaction = myTrans_DE
CMD_FZ.CommandText = "delete from CWB_FZ where cwid=" & ID_DE
FZ_SL = CMD_FZ.ExecuteNonQuery()

Catch ex As Exception
MsgBox(ex.Message.ToString & "cw del_cw", 48, "系统提示")
DE_SL = 0

Finally
CMD_DE_CW.Dispose()
CMD_FZ.Dispose()
CMD_DE_CW = Nothing
CMD_FZ = Nothing
If FZ_SL >= 1 And DE_SL = 1 And XH_SL = 1 Then
DEL_ADD_CW = "操作成功,删除了" & DE_SL & " 条财务记录," & FZ_SL & "条财务辅助记录,更新了" & XH_SL & "条业务记录的实收!"
Else
DEL_ADD_CW = "操作失败"
End If

End Try
End Function

End While
REA_CW.Close()
CN.lost_c() '关闭连接,释放资源
CN = Nothing
amandag 2007-07-14
  • 打赏
  • 举报
回复
贴代码看看
southpig 2007-07-14
  • 打赏
  • 举报
回复
重启电脑,应该就会有错误提示了
johnny1983 2007-07-14
  • 打赏
  • 举报
回复
给一下代码
liubaohuazy 2007-07-14
  • 打赏
  • 举报
回复
在顶下
liubaohuazy 2007-07-14
  • 打赏
  • 举报
回复
连接和datareader都关闭了。每次都从新定义了。(已经牺牲了速度了)
hm7921936 2007-07-13
  • 打赏
  • 举报
回复
datareader独占连接的对象的.~
hm7921936 2007-07-13
  • 打赏
  • 举报
回复
关闭连接了吗? 每次?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧