By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,033 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,033 IT Pros & Developers. It's quick & easy.

sqlreader Do...while problem

P: n/a
drBranchForm = sqldatareader
For Each drBranch In dtUserBranch
Do While drBranchForm.Read
.......... Problem (A)
Loop
Next

I found that the datarreader only loop onces , ?? How can I make it restart
the sqldatareader ???
Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Here is an working example. Would have to see more of your code to
figure out the problem you are having.

Dim conn As SqlConnection

Dim strConn As String

Dim drCustomer As SqlDataReader

Dim daCustomer As SqlDataAdapter

Dim cmd As SqlCommand

Dim ds As New DataSet

strConn = "Server = " & Environment.MachineName & ";"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

cmd = New SqlCommand("Select * from Customers", conn)

conn.Open()

drCustomer = cmd.ExecuteReader

Do While drCustomer.Read

Trace.WriteLine(drCustomer.Item("CustomerID").ToSt ring)

Loop

conn.Close()

Ken

-----------------------------------

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
drBranchForm = sqldatareader
For Each drBranch In dtUserBranch
Do While drBranchForm.Read
.......... Problem (A)
Loop
Next

I found that the datarreader only loop onces , ?? How can I make it restart
the sqldatareader ???
Thanks

Nov 21 '05 #2

P: n/a
Do you know if you have many transaction you need to call NextResult ??

again, need to provide us more code please ^_^

From http://www.developmentnow.com/g/38_2...ile-problem.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
Nov 21 '05 #3

P: n/a
However you can just try something like this.
Dim drBranchForm As SqlDataReader
drBranchForm = myCommand.ExecuteReader()
' Always call Read before accessing data.
While drBranchForm.Read()
Console.WriteLine(( drBranchForm.GetInt32(0) & ", " & drBranchForm.GetString(1)))
End While
' always call Close when done reading.
drBranchForm.Close()

take out the FOR EACH loop first.

Hope this can help ^_^
From http://www.developmentnow.com/g/38_2...le-problem.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.