B
Bill Schanks
I have this code, that will take what is in a listview and go get more
info. Howerver on a large number of listview records this will produce
a problem (Say if I had 30,000 Listview entires).
What would be the recommended alternative? Have it load the listview
items to a table and then have my query join to that table, Put in a
check and if there are >1000 listview entires don't allow the sql
lookup?
<<snip>>
Try
sSQL = "SELECT PreferredID, LastName, FirstName, Phone,
Email, ManagerPreferredID, JobFamily, " _
& "CostCenterNbr, CostCenterName FROM dbo.Employee "
'Construct Where Clause
For Each item As ListViewItem In lvMembers.Items
If Not sb.Length = 0 Then sb.Append(", ")
sb.Append("'" & item.Text & "'")
Next
sSQL = sSQL & "WHERE PreferredID IN (" & sb.ToString & ")
" _
& "ORDER BY LastName, FirstName"
'Clear list view out
Me.lvMembers.Clear()
'Fetch new results
ShowBusy("Querying database...")
iCount = 0
Using connection As New SqlConnection(g_sSQL_CONN)
Dim command As New SqlCommand(sSQL, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader
'Setup columns
For i = 0 To reader.FieldCount - 1
lvwColumn = New ColumnHeader
lvwColumn.Text = reader.GetName(i)
lvwColumn.Width = 80
Me.lvMembers.Columns.Add(lvwColumn)
Next
Do While reader.Read
itmListItem = New ListViewItem
itmListItem.Text = CStr(reader(0))
For i = 1 To reader.FieldCount - 1
If reader.IsDBNull(i) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(reader.GetString(i))
End If
Next i
lvMembers.Items.Add(itmListItem)
iCount = iCount + 1
Loop
'Close connection
reader.Close()
End Using
<<Snip>>
info. Howerver on a large number of listview records this will produce
a problem (Say if I had 30,000 Listview entires).
What would be the recommended alternative? Have it load the listview
items to a table and then have my query join to that table, Put in a
check and if there are >1000 listview entires don't allow the sql
lookup?
<<snip>>
Try
sSQL = "SELECT PreferredID, LastName, FirstName, Phone,
Email, ManagerPreferredID, JobFamily, " _
& "CostCenterNbr, CostCenterName FROM dbo.Employee "
'Construct Where Clause
For Each item As ListViewItem In lvMembers.Items
If Not sb.Length = 0 Then sb.Append(", ")
sb.Append("'" & item.Text & "'")
Next
sSQL = sSQL & "WHERE PreferredID IN (" & sb.ToString & ")
" _
& "ORDER BY LastName, FirstName"
'Clear list view out
Me.lvMembers.Clear()
'Fetch new results
ShowBusy("Querying database...")
iCount = 0
Using connection As New SqlConnection(g_sSQL_CONN)
Dim command As New SqlCommand(sSQL, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader
'Setup columns
For i = 0 To reader.FieldCount - 1
lvwColumn = New ColumnHeader
lvwColumn.Text = reader.GetName(i)
lvwColumn.Width = 80
Me.lvMembers.Columns.Add(lvwColumn)
Next
Do While reader.Read
itmListItem = New ListViewItem
itmListItem.Text = CStr(reader(0))
For i = 1 To reader.FieldCount - 1
If reader.IsDBNull(i) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(reader.GetString(i))
End If
Next i
lvMembers.Items.Add(itmListItem)
iCount = iCount + 1
Loop
'Close connection
reader.Close()
End Using
<<Snip>>