sqlreader Do...while problem

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

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
 
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").ToString)

Loop

conn.Close()



Ken

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

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
 
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_2005_3_0_0_371001/sqlreader-Do---while-problem.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top