数据读取器关闭选项 [英] Data reader closed option

查看:118
本文介绍了数据读取器关闭选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个问题.

我首先打开连接.然后我写sql statement1,然后使用阅读器(我不想关闭此阅读器).我使用了sql statement2,然后再次使用了另一个阅读器(我也不想在这里关闭).

我的问题是,当我打开连接时,我想读取两个sql语句而又不关闭另一个读取器.我想在完成阅读的sql语句完成后关闭,然后只有我想关闭两个阅读器.

该怎么做.

这是我的代码:

Hi,

I have one problem.

I first open the connection. then i write sql statement1 followed by reader is used(i don''t want close this reader). i used sql statement2 and again i used another reader(i don''t want to close here also).

my problem is when i open the connecition and i want to read both sql statement without closing the reader one within the another. i want to close once icompleted my reading sql statement is finisehed then only i want to close both reader.

how to do that.

Here is my code:

<% 
    Conn.Open() 
    StrQry = "" 
    StrQry = "Select emp_number,emp_name + ' ' + emp_initial as name,emp_designation,Manpower_Division_ID from idpeapp.dbo.view_employee where emp_dept ='" & Session("Dept") & "' order by Manpower_Division_ID,emp_name" 
    CmdEmp.Connection = Conn 
    CmdEmp.CommandText = StrQry 
    RdrEmp = CmdEmp.ExecuteReader 
    Dim i As Integer = 1 
    If RdrEmp.HasRows Then 
        Dim row As Integer = 1 
        Dim col As Integer = 1 
        Dim Manpower_Division_ID As Integer = 1 
        While RdrEmp.Read
%>
<% 
        If Manpower_Division_ID <> RdrEmp("Manpower_Division_ID") Then 
%>
    <tr>
        <td align="left" colspan="18">
            Designers
        </td>
    </tr>
<% 
            i = 1 
        End If 
%>
    <tr>
        <td>
            <%Response.Write(i)%>
        </td>
    <td>
<%
        Response.Write(RdrEmp("name") & " (" & RdrEmp("emp_number") & ")")
%>
        </td>
<% 
        'Conn.Open() 
        StrQry = "" 
        StrQry = "Select Designation,DesigCode,Priority,Priority2,ProfRoleCode,ProfRole,DeptCode from Designation where DeptCode='" & Session("Dept") & "' order by Priority2" 
        CmdDesign.Connection = Conn 
        CmdDesign.CommandText = StrQry 
        RdrDesign = CmdDesign.ExecuteReader 
        If RdrDesign.HasRows Then 
            col = 1 
            While RdrDesign.Read
%>
                <td align="center" title="<%=RdrDesign("Designation")%>">
<%
                Response.Write(FindVal(RdrEmp("Emp_number"), RdrDesign("DesigCode")))
%>
        </td>
<% 
                col = col + 1 
            End While 
        End If 
%>
    </tr>
<% 
        row = row + 1 
        i = i + 1 
        Manpower_Division_ID = RdrEmp("Manpower_Division_ID") 
    End While 
End If 
%>
    <% %>

推荐答案

您没有关闭阅读器-完全没有.连接是关闭的(我看不到您在哪里做.

最后,考虑将这段代码移到aspx.vb文件中.它将更具可读性(和可调试性).
You don''t close the reader - at all. The connection is what''s closed (and I don''t see where you''re doing that.

Lastly, consider moving this code into the aspx.vb file. It will be much more readable (and debuggable).


在先经过而后结束"之后,您可以关闭

After First While End you can close

rDRDesign.Close()



并在第二个阅读器关闭后第二秒.



and after second while close sencond reader.


这篇关于数据读取器关闭选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆