想实现先从表中查询出记录列,将列值作为参数在循环内部继续查询,如下代码,这在asp当中很常见,现在不灵了,请问错在哪里?该如何嵌套使用datareader
Sub show1
Dim queryString As String = "select bumen from workflo2_bumen order by paixu"
Dim queryString1 As StringUsing 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"">&nbsp;</td>")
response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
response.Write("   <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
response.Write(" </tr>")
End While
reader.Close()
End Using
end subERROR [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

解决方案 »

  1.   

    问题已解决,新建连接connection使用就可以了
    .net下不像asp中的conn可以重复使用吗?
    Sub show1
    Dim queryString As String = "select * from workflo2_bumen order by paixu"
    Dim queryString1 As StringUsing 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(1) & "</font></a></td>")

    Using connection1 As New OdbcConnection("DSN=yuangongyingxiao;uid=yuangongyingxiao;pwd=yuangongyingxiao77**")
    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"
    response.Write(querystring1)
    'response.End()
    Dim command1 As New OdbcCommand(queryString1, connection1)
    connection1.Open()
    Dim reader1 As OdbcDataReader = command1.ExecuteReader()
    While reader1.Read()
    response.Write(reader1.getString(0))
    guhua = guhua + reader1.getString(0)
    End While
    reader1.Close()
    end using
    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"">&nbsp;</td>")
    response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
    response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
    response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
    response.Write("  <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
    response.Write("   <td align=""right"" nowrap style=""border-bottom:1px dotted #8A9DC6;border-right:1px dotted #8A9DC6"">&nbsp;</td>")
    response.Write(" </tr>")
    End While
    reader.Close()
    End Using
    end sub
      

  2.   

    别说,一毛一样的功能,内含300次查询,.net比asp快一些,减少运行时间20%以上
    对比数据,秒
    .net    asp
    10   20
    12   62
    15   19
    13   18
    14   17