首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

DataReader报错解决思路

2011-12-26 
DataReader报错运行下面代码报错“已有打开的与此命令相关联的 DataReader,必须首先将它关闭。” 通过查询结

DataReader报错
运行下面代码报错“已有打开的与此命令相关联的 DataReader,必须首先将它关闭。” 通过查询结果再查询同库中另一张表,用DataReader报错,请问怎么解决?  
  SqlCon.Open()
  SqlRead = SqlCom.ExecuteReader
  While SqlRead.Read
  FieldCod = SqlRead.Item("字段代码")
  StrSQL1 = "select count(*) from [Dictionary].[数据编码] where [字段代码]='" & FieldCod & "'"
  SqlCom1 = New DS.SqlCommand(StrSQL1, SqlConFer)
  If SqlCom1.ExecuteScalar > 0 Then
  mesgbox ""
end if
  End While
  SqlCon.Close()

[解决办法]
在While中另外声明SqlConnection和SqlCommand

热点排行