System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭
FunctionIndustrybigclass(ByValclassnameAsString)AsStringDimclassCmdAsSqlCommandDimlis...
Function Industrybigclass(ByVal classname As String) As String
Dim classCmd As SqlCommand
Dim listCmd As SqlCommand
Dim listReader As SqlDataReader
Dim IndustryID As Integer
Dim connectionString As String = GetConnectionString()
Dim classSql As String = "Select ID, Industry, IndustryID, Sequence From Industry Where IndustryID = 0 and classname='"& classname &"' Order By Sequence Desc, ID Asc"
Dim listSql As String ="Select ID, Industry, IndustryID, Sequence From Industry Where IndustryID = " & IndustryID & " Order By Sequence Desc, ID Asc"
Using awConnection As New SqlConnection(connectionString)
classCmd = New SqlCommand(classSql, awConnection)
listCmd = New SqlCommand(listSql, awConnection)
listCmd.Parameters.Add("@IndustryID", SqlDbType.Int)
awConnection.Open()
Using classReader As SqlDataReader = classCmd.ExecuteReader()
While classReader.Read()
Console.WriteLine("<dl><dt><a href=""search.aspx?industryid=" & classReader.GetValue(classReader.GetOrdinal("ID")) & ">" & classReader.GetValue(classReader.GetOrdinal("Industry")) & "</a></dt><dd class='list'><ul>")
IndustryID = CInt(classReader("ID"))
listCmd.Parameters("@IndustryID").Value = IndustryID
listReader = listCmd.ExecuteReader()
Using listReader
While listReader.Read()
Console.WriteLine(CStr(listReader("Industry")))
End While
listReader.Close()
End Using
Console.WriteLine("</ul></dd><dd class='more'><a href=""search.aspx?industryid=" & classReader.GetValue(classReader.GetOrdinal("ID")) & " target=""_blank"">更多>></a></dd></dl>")
End While
classReader.Close()
End Using
End Using
End Function
异常详细信息: System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
源错误:
行 80: IndustryID = CInt(classReader("ID"))
行 81: listCmd.Parameters("@IndustryID").Value = IndustryID
行 82: listReader = listCmd.ExecuteReader()
行 83:
行 84: Using listReader
82行出错 展开
Dim classCmd As SqlCommand
Dim listCmd As SqlCommand
Dim listReader As SqlDataReader
Dim IndustryID As Integer
Dim connectionString As String = GetConnectionString()
Dim classSql As String = "Select ID, Industry, IndustryID, Sequence From Industry Where IndustryID = 0 and classname='"& classname &"' Order By Sequence Desc, ID Asc"
Dim listSql As String ="Select ID, Industry, IndustryID, Sequence From Industry Where IndustryID = " & IndustryID & " Order By Sequence Desc, ID Asc"
Using awConnection As New SqlConnection(connectionString)
classCmd = New SqlCommand(classSql, awConnection)
listCmd = New SqlCommand(listSql, awConnection)
listCmd.Parameters.Add("@IndustryID", SqlDbType.Int)
awConnection.Open()
Using classReader As SqlDataReader = classCmd.ExecuteReader()
While classReader.Read()
Console.WriteLine("<dl><dt><a href=""search.aspx?industryid=" & classReader.GetValue(classReader.GetOrdinal("ID")) & ">" & classReader.GetValue(classReader.GetOrdinal("Industry")) & "</a></dt><dd class='list'><ul>")
IndustryID = CInt(classReader("ID"))
listCmd.Parameters("@IndustryID").Value = IndustryID
listReader = listCmd.ExecuteReader()
Using listReader
While listReader.Read()
Console.WriteLine(CStr(listReader("Industry")))
End While
listReader.Close()
End Using
Console.WriteLine("</ul></dd><dd class='more'><a href=""search.aspx?industryid=" & classReader.GetValue(classReader.GetOrdinal("ID")) & " target=""_blank"">更多>></a></dd></dl>")
End While
classReader.Close()
End Using
End Using
End Function
异常详细信息: System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
源错误:
行 80: IndustryID = CInt(classReader("ID"))
行 81: listCmd.Parameters("@IndustryID").Value = IndustryID
行 82: listReader = listCmd.ExecuteReader()
行 83:
行 84: Using listReader
82行出错 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询