我必須做點什麼昨天相似。我的方法是建立一個我必須保存在我的數據庫中的列表,然後將其序列化爲XML。我將XML作爲參數傳遞給存儲過程,然後處理它並保存數據。
總的來說,我會說這是不是調用DATABSE多次爲您的應用程序得到它都想保存的數據,它給你的數據庫在一個事務中更有效的解決方案。
由於你如何能做到這這裏的例子是我的代碼,其循環通過的CheckBoxList,並創建一個選擇項的列表將其序列化爲XML。您應該可以輕鬆地使其適用於您的ListBox
' This is the list that will hold each of our selected items
Dim listOfSelectedItems As New List(Of ListItem)
' Loop through the CheckBoxList control and add all selected items to
' the listOfSelectedItems List if the item has its Selected property
' set to true
For Each item As ListItem In chkNotify.Items
If (item.Selected = True) Then
listOfSelectedItems.Add(item)
End If
Next
' Declare a new XMLSerializer
Dim serializer As New XmlSerializer(listOfSelectedItems.GetType)
' Declare a StringWriter
Dim writer As StringWriter = New StringWriter()
' Serialize the listOfSelectedItems List
serializer.Serialize(writer, listOfSelectedItems)
' Store our XML in a String variable
Dim serializedXML As String = writer.ToString()