There is already an open DataReader associated with this Con
Hi Sir,
I am getting the following error while executing the function.Will u plz clear ma doubt.Its urgent
"There is already an open DataReader associated with this Con"
The function is
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Session("strWarehouse") = ddlWarehouse.SelectedValue
Session("strSesUser") = ViewState("strUser")
Session("strSesGrpComp") = ViewState("strGrpComp")
Session("strSesComp") = ViewState("strComp")
Session("strSesCompName") = ViewState("strCompName")
Session("cFYear") = ViewState("cFYear")
Dim dIniQty, dTranQty, dBalQty As Decimal
Dim dPrevBal As Decimal
Dim cItem, cPrevItem, strQuery As String
Dim iInvTran As Integer
Dim conAcctGrp As New SqlConnection(conString)
Dim rdrCheck1, rdrCheck As SqlDataReader
Dim cmdJourDetail As New SqlCommand()
Dim conAcct As New SqlConnection(conString)
strQuery = "SELECT " & _
" cItem, iInvTran,dIniQty,dTranQty,dBalQty FROM loitm101 " & _
" WHERE cGrpComp = '" & Trim(ViewState("strGrpComp")) & "' and cComp = '" & Trim(ViewState("strComp")) & "'" & _
" and cWarehouse='" & ddlWarehouse.SelectedItem.Text.Substring(0, 5) & "'" & _
" and cItem='" & ddlItem.SelectedItem.Text.Substring(0, 12) & "' " & _
" ORDER BY cItem, iInvTran "
conAcctGrp.Open()
cmdJourDetail.Connection = conAcctGrp
cmdJourDetail.CommandText = strQuery
rdrCheck = cmdJourDetail.ExecuteReader()
Do While rdrCheck.Read
cItem = rdrCheck("cItem")
iInvTran = rdrCheck("iInvTran")
dIniQty = rdrCheck("dIniQty")
dTranQty = rdrCheck("dTranQty")
dBalQty = rdrCheck("dBalQty")
'If item = previtem And (((initqty + transqty) <> balqty) Or (initqty <> prevbalqty)) Then
'add to grid
'End If
If cItem = cPrevItem And ((dIniQty + dTranQty) <> dBalQty Or (dIniQty <> dPrevBal)) Then
conAcct.Open()
strQuery = "Update loitm101 set dIniQty='" & dPrevBal & "',dBalQty='" & dPrevBal + dTranQty & "' where cGrpComp = '" & ViewState("strGrpComp") & "' and cComp='" & ViewState("strComp") & "' and cItem='" & ddlItem.SelectedItem.Text.Substring(0, 12) & "' and cWarehouse='" & ddlWarehouse.SelectedItem.Text.Substring(0, 5) & "' and iInvTran='" & iInvTran & "' "
cmdJourDetail.CommandText = strQuery
cmdJourDetail.ExecuteNonQuery()
conAcct.Close()
End If
dPrevBal = dBalQty
cPrevItem = cItem
If cItem <> cPrevItem Then
Dim cdBalQtyfinal As String
strQuery = "SELECT dBalQty FROM loitm101 where cGrpComp = '" & ViewState("strGrpComp") & "' and cComp='" & ViewState("strComp") & "' and cItem ='" & ddlItem.SelectedItem.Text.Substring(0, 12) & "' and cWarehouse='" & ddlWarehouse.SelectedItem.Text.Substring(0, 5) & "' and iInvTran='" & iInvTran & "' "
conAcct.Open()
cmdJourDetail.Connection = conAcct
cmdJourDetail.CommandText = strQuery
rdrCheck = cmdJourDetail.ExecuteReader()
Do While rdrCheck.Read()
cdBalQtyfinal = rdrCheck("dBalQty")
Loop
conAcct.Close()
strQuery = "Update loitm025 set dBalQty='" & cdBalQtyfinal & "' where cGrpComp = '" & ViewState("strGrpComp") & "' and cComp='" & ViewState("strComp") & "' and cItem ='" & ddlItem.SelectedItem.Text.Substring(0, 12) & "' and cWarehouse='" & ddlWarehouse.SelectedItem.Text.Substring(0, 5) & "' "
cmdJourDetail.CommandText = strQuery
cmdJourDetail.ExecuteNonQuery()
End If
Loop
conAcctGrp.Close()
End Sub
Plz consider ma question plzzzzzzzzzzzzzzzzz