lundi 2 mars 2015

Data reader is reading and returning results twice


Vote count:

0




I'm just trying to read info from a database and store it in a listview, and it works, but I get a duplicate result set. It seems like my loop keeps going.



Connection.Open()

Command = Connection.CreateCommand
Command.CommandText = "SELECT * FROM Data"

myreader = Command.ExecuteReader
Dim mItem As ListViewItem
ListView1.View = View.Details
Dim i As Integer = myreader.FieldCount

For ii As Integer = 0 To i - 1
ListView1.Columns.Add(myreader.GetName(ii))


Next
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
While myreader.Read
'MessageBox.Show(reader.Item("Name"))
mItem = ListView1.Items.Add(myreader(("Extension")))
mItem.SubItems.Add(myreader("FirstName"))
mItem.SubItems.Add(myreader("LastName"))
End While
Command.Dispose()
Connection.Close()


As I said, this does almost everything that it should.


Here is something I can't figure out: I take this SAME EXACT code and move it to another project, I just changes the names of the columns/tables and so on, and it reads and inserts into my listview PERFECTLY.


It's just in this particular case that I get duplicates.


There aren't any duplicates in my DB either.


My 'While' loop keeps reading for some reason. I can't figure it out.



asked 1 min ago

Bill

13






Data reader is reading and returning results twice

Aucun commentaire:

Enregistrer un commentaire