Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
<% 
    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 
%>
    <% %>
Posted
Updated 5-Jul-11 23:34pm
v3
Comments
R. Giskard Reventlov 6-Jul-11 5:12am    
Format your code: it's unreadable!!!
gani7787 6-Jul-11 5:15am    
Code is below.

<% 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
%>
<%

%>

Any help...
#realJSOP 6-Jul-11 5:25am    
No - he meant format it in the original question.
#realJSOP 6-Jul-11 5:35am    
Have you ever heard of "code-behind"?

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).
 
Share this answer
 
After First While End you can close

rDRDesign.Close()


and after second while close sencond reader.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900