datareader嵌套的问题
想实现先从表中查询出记录列,将列值作为参数在循环内部继续查询,如下代码,这在asp当中很常见,现在不灵了,请问错在哪里?该如何嵌套使用datareader
Sub show1
Dim queryString As String = "select bumen from workflo2_bumen order by paixu "
Dim queryString1 As String
Using connection As New OdbcConnection( "DSN=yuangongyingxiao;uid=yuangongyingxiao;pwd=yuangongyingxiao77** ")
Dim command As New OdbcCommand(queryString, connection)
connection.Open()
Dim reader As OdbcDataReader = command.ExecuteReader()
While reader.Read()
'response.write(reader.getString(0)& " | "&reader.getString(1) & " <br> ")
response.Write( " <tr> ")
response.Write( " <td align= " "center " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-left:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> <a href= " "huizhi.asp " "> <font color= " "#FFFFFF " "> " & reader.getString(0) & " </font> </a> </td> ")
queryString1 = "select count(g_lanshoudanwei) from workflo2_guhua where g_lanshoudanwei= ' " & reader.getString(0) & " ' and n1_daodashijian > = ' "& DateLimit_1 & " ' and n1_daodashijian <= ' "& DateLimit_2 & " ' and g_jungongshijian is not null "
Dim command1 As New OdbcCommand(queryString1, connection)
Dim reader1 As OdbcDataReader = command1.ExecuteReader()
While reader.Read()
response.Write(reader1.getString(0))
guhua = guhua + reader1.getString(0)
End While
reader1.Close()
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " <td align= " "right " " nowrap style= " "border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6 " "> </td> ")
response.Write( " </tr> ")
End While
reader.Close()
End Using
end sub
ERROR [HY000] [Microsoft][SQL Native Client]连接繁忙导致另一个命令
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.Odbc.OdbcException: ERROR [HY000] [Microsoft][SQL Native Client]连接繁忙导致另一个命令
源错误:
行 59: queryString1 = "select count(g_lanshoudanwei) from workflo2_guhua where g_lanshoudanwei= ' " & reader.getString(1) & " ' and n1_daodashijian > = ' "& DateLimit_1 & " ' and n1_daodashijian <= ' "& DateLimit_2 & " ' and g_jungongshijian is not null "
行 60: Dim command1 As New OdbcCommand(queryString1, connection)
行 61: Dim reader1 As OdbcDataReader = command1.ExecuteReader()
行 62: While reader.Read()
行 63: response.Write(reader1.getString(0))
源文件: D:\wwwroot\yuangongyingxiao8882\dc_default.aspx 行: 61
[解决办法]
datareader 独占连接