nutsch
asked on
SqlDataReader doesn't Read() even though it HasRows
Hi Experts,
I'm building a javascript string from a code-behind page with data retrieved from a sql database.
The datareader has rows, but it doesn't read. If I build the string outside of the read loop, it works (but only retrieves the first line). What am I doing wrong?
THanks for your help
I'm building a javascript string from a code-behind page with data retrieved from a sql database.
The datareader has rows, but it doesn't read. If I build the string outside of the read loop, it works (but only retrieves the first line). What am I doing wrong?
THanks for your help
Function sFnLoadCodingLines() As String
Dim cmdCoding As SqlCommand, drCoding As SqlDataReader, con As New SqlConnection(strcon)
Dim sTemp As String = ""
Dim lInvoiceID As Long
lInvoiceID = CLng(Page.Request.QueryString("InvoiceID"))
cmdCoding = New SqlCommand
cmdCoding.CommandText = "SELECT BU,DEPT,AccNo,Qty,Amount,Description,EMP,VARIETAL,BRAND,STATE,PROJECT FROM OI_tblCoding WHERE isDeleted=0 AND InvoiceID=" & lInvoiceID
cmdCoding.Connection = con
con.Open()
drCoding = cmdCoding.ExecuteReader
drCoding.Read()
If drCoding.HasRows() Then
While drCoding.Read()
'addRowToTable(sBU, sDPT, sAcct, dbQty, dbAmt, sDesc, sEmp, sVar, sBrand, sState, sProj)
sTemp = sTemp & "addRowToTable(""" & drCoding("BU").ToString & _
""",""" & drCoding("DEPT").ToString & _
""",""" & drCoding("AccNo").ToString & _
""",""" & drCoding("Qty").ToString & _
""",""" & drCoding("Amount").ToString & _
""",""" & drCoding("Description").ToString & _
""",""" & drCoding("EMP").ToString & _
""",""" & drCoding("VARIETAL").ToString & _
""",""" & drCoding("BRAND").ToString & _
""",""" & drCoding("STATE").ToString & _
""",""" & drCoding("PROJECT").ToString & """);" & vbCrLf
End While
sFnLoadCodingLines = sTemp
Else
sFnLoadCodingLines = ""
End If
con.Close()
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for pointing out the error of my ways,
Thomas