I have this problem that prevents me to collect a proper set of data.
I want to Foreach the items from a listbox and split the items.
The splitted items must be store in a single Array
I have this syntax.
while (reader.Read())
{
var tmp = reader["Items"];
if (tmp != DBNull.Value)
{
ListBox1.Items.Add(tmp.ToString());
}
}
foreach (var items in ListBox1.Items)
{
myDb.Add(new MyItems() { string.Join(",", items) } );
}
The result I got from this process is a single data in 1 array, not multiple.
Actual Result:
{"ItemA,ItemB,ItemC,ItemD"}
Expected Result:
{ "ItemA", "ItemB", "ItemC", "ItemD" }
I found this usefull:
Here[
^]
and I have this syntax now.
IEnumerable<string> row;
IEnumerable<string> permutations;
while (reader.Read())
{
var tmp = reader["Items"];
if (tmp != DBNull.Value)
{
ListBox1.Items.Add(tmp.ToString());
}
}
row = new string[] {ListBox1.Items.ToString()};
permutations = GetPermutations(row, delimiter: ",");
foreach (var permutation in permutations)
{
myDb.Add(new MyItems() {permutation});
}
Error: {System.Web.UI.WebControls.ListItemCollection}