Add an array of string/single string to required columns in datatable

Hello Everyone

I have a queue item of different values, each value may be a single string or comma separated string

Eg1 : Loan#: 234567
Eg2 : CompanyName : 234156, 345678, 456344 etc

Eg1 : CompanyName : Luna
Eg2 : CompanyName : Luna, Motors, Crafts etc

Eg1 : Email address: Luna@gmailcom, Motors@gmailcom,Crafts@gmailcom
Eg2 : Email address: Luna@gmailcom

Eg1 : property county: King, English
Eg2 : property county: King

with many different values
I need to build a datatable from these different keys of queue item

Datatable Eg : Loan#, CompanyName, Email address, property county

How to populate the above datatable with the values from queue item , which approach is best

Thanks in advance

@ppr @Palaniyappan

from the above given samples we cannot derive all needed constraints

We assume:

  • Data is from the SpecificContent Dictionary
  • all values are strings

how many dictionary keys are to expect? Only 2 or can it be more also?

Yes Data is from specificcontent dictionary and all are strings
Its is more than 2, its totally 9 columns/dictionary keys

then please give us a sample for 3 keys where also the delimited values are of different length like

Key Value
A VA1
B VB1,VB2
C VC1, VC2, VC3

what should be the expected output datatable in detail for above sample

Queue Item (Transaction Item)
Loan# (str) : 345677,456784,678904
CompanyName (str) : Luna, Motors, Crafts
Email address (str): Luna@gmailcom
property county (str) : King, English,King

output datatable

Loan# CompanyName Email address property county
345677 Luna Luna@gmailcom King
456784 Motors Luna@gmailcom English
678904 Crafts Luna@gmailcom King

unfortunately our question of

is unanswered

About above:

Assign Activity:
dtData | DataType: DataTable = new DataTable()

For Each Activity | item in yourSpecificContentDict.Keys

  • Add DataColumn: ColumnName: item, DataTable: dtData

Assign Activity:
myDict2 | Dictionary(Of String, String()) =

(From kvp In myDict
Let arrSplits = kvp.Value.ToString().Split(",".ToCharArray, StringSplitOptions.RemoveEmptyEntries).Select(Function (x) x.Trim).ToArray
Select t = Tuple.Create(kvp.Key, arrSplits)).ToDictionary(Function (t) t.Item1, Function (t) t.Item2)

Assign Activity:
ArrayMaxLength | int32 =
myDict2.Values.Max(Function (x) x.Length)

Assign Activity:
dtData =

(From i In Enumerable.Range(0, ArrayMaxLength)
Let rap = myDict2.Keys.Select(Function (k) If( i < myDict2(k).Length , myDict2(k)(i), myDict2(k).FirstOrDefault) )
Let ra = rap.Cast(Of Object).ToArray
Select r = dtData.Rows.Add(ra)).CopyToDataTable

grafik

However, we recommend adapting above described Prototype and make it more resilient on different length arrays. Also feel free to decompose the LINQs to essential activities