Reputation: 1753
I have some code that loops through a listview and puts the values into 'output1' & 'output2'. However, what is happening is that the results are strung together like thus: 0307NG77775660NG7778. How do I split so that I can include in access db.
There are 2 columns in the listview and they contain values in the format of:
1st row 0307 - NG7777, 2nd row 5660 - 7778 etc. This is a desktop winforms code. Thanks
Dim BoxList As New List(Of String)
Dim BoxItem As String
Dim CustRefList As New List(Of String)
Dim CustRef As String
For Each item As ListViewItem In Me.lvSelectedItems.Items
Dim box As String = item.Text
BoxItem = item.SubItems.Item(1).Text
BoxList.Add(box)
output2 += BoxItem
Dim cust As String = item.Text
CustRef = item.SubItems.Item(1).Text
CustRefList.Add(cust)
output1 += CustRef
Next
output = String.Join(" "c, BoxList.ToArray(), CustRefList.ToArray())
Dim cmd As OleDbCommand = New OleDbCommand("Insert into Temp (temp, [class]) Values ('" & output1 & "', '" & output2 & "')", oledbCnn)
dr = cmd.ExecuteReader
Upvotes: 0
Views: 682
Reputation: 26424
Make username a List(Of String)
, then just do:
usernameList.Add(username) 'instead of output1 += username
When done with the loop, do this:
output1 = String.Join(" "c, usernameList.ToArray())
You can pick a join character of your choice (if you don't like spaces " "
).
EDIT: Example:
Dim usernameList As New List(Of String)
Dim session As String
For Each item As ListViewItem In Me.lvSelectedItems.Items
Dim username As String = item.Text
session = item.SubItems.Item(1).Text
usernameList.Add(username)
output2 += session
Next
output1 = String.Join(" "c, usernameList.ToArray())
Upvotes: 1