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