datareader的问题!!!!! 我在一个类里的一个
方法用到了datareader对象,并在
方法结束前将他close了.可是我在用这个类建立了两个对象时,第二个对象在用到了这个
方法时却总是
提示:已有打开的与此命令相关联的 DataReader,必须首先将它
关闭.如何
解决啊!!! __________________________________________________________________________ 说明你同1个
链接同时打开了2个datareader,必须先
关闭1个datareader,要么就开第2个datareader的时候用个新的
链接 __________________________________________________________________________ 1/ 我的连接是对象的一个
属性,是在对象new时传递进去的.难道连接传递的是地址吗? 2/ 在我的类的
方法里,在最后已经进行了close为什么还是不行呢? __________________________________________________________________________ 1/ 我的连接是对象的一个
属性,是在对象new时传递进去的.难道连接传递的是地址吗? ----------------------- 你传的是同1个
链接吧,你有没有new2次
链接就知道了 2/ 在我的类的
方法里,在最后已经进行了close为什么还是不行呢? -------------------------- 一起
错误的原因是在你close之前就又开了1个DataReader。 PS:最好贴出你的
代码看看 __________________________________________________________________________ 原码如下: Public Sub CongGouToDB(ByVal datetime As Date) geshi = Split(my_
Meta1.FileFieldOrder,",") geshi1 = Split(my_
Meta1.attributeOrder,": ") geshi2 = Split(my_
Meta1.attributeOrder1,": ") zidonggeshi1 = Split(my_
Meta2.attributeOrder,": ") zidonggeshi2 = Split(my_
Meta2.attributeOrder1,": ") Dim mycommandstr As String Dim mycommand1 As
sqlCommand Dim myreader3 As
sqlDataReader Dim count As Boolean mycommandstr = "SELECT * FROM " + Trim(my_
Meta1.tableName) + " where StationID = '' " + Trim(my_
Meta1.stationID) + " '' and ObservDate= '' " + datetime.ToShortDateString + " ''and ObservTime= '' " + datetime.ToLongTimeString + " '';SELECT * FROM " + my_
Meta2.tableName + " where StationID = '' " + my_
Meta2.stationID + " '' and ObservDate= '' " + datetime.ToShortDateString + " ''and ObservTime= '' " + datetime.ToLongTimeString + " '' " mycommand1 = New
sqlCommand(mycommandstr,myconnection) myreader3 = mycommand1.ExecuteReader() 这句是出错的地方!!!! count = myreader3.Read() Dim i,k,j As Integer For i = 0 To geshi2.Length - 1 k = CType(geshi2(i),Integer) j = CType(geshi1(i + 1),Integer) If count Then melement(k,0) = myreader3(j) Else melement(k,0) = DBNull.Value.ToString End If melement(k,1) = "0 " Next myreader3.NextResult() count = myreader3.Read() For i = 0 To zidonggeshi2.Length - 1 k = CType(zidonggeshi2(i),Integer) j = CType(zidonggeshi1(i + 1),1) = "0 " Next myreader3.Close() mycommand1.Dispose() End Sub 这是类里的一个
方法> .. __________________________________________________________________________ 你前面1个
方法了,
调用CongGouToDB
方法之前
调用的
方法. __________________________________________________________________________
原文链接:https://www.f2er.com/vb/264100.html