I have one question here regarding the String.Split to create a DataRow or specifically adding data to row in DataTable. Let say I have this:
Dim dt As New DataTable
Dim str As String = "Data1,Data2,Data3,Data4"
And I wanted to get the data from String str into the DataTable dt, split by "," .
Traditionally, I achieve this by using String.Split and this is how I do it:
Dim temp() As String = str.Split(",")
Dim dr As DataRow = dt.NewRow
dr("Col1") = temp(0)
dr("Col2") = temp(1)
dr("Col3") = temp(2)
dr("Col4") = temp(3)
dt.Rows.Add(dr)
Or
dt.Rows.Add(temp(0), temp(1), temp(2), temp(3))
This should be fine if it involve only few columns of data. What if I have like 50 columns of DataTable or even more. Is there are any steps that I could directly assign String.Split to the DataRow or DataTable.Rows. Or other method that can help me to insert the data from a String into my DataTable.
I am so sorry if any of you were unable to understand my English. Please comment for anything that was unclear and I really need guide into this as I am new to this programming world.
Thank you.
Add. - jmcilhinneyObject(). You can easily create anObjectarray though:temp.Cast(Of Object)().ToArray(). - jmcilhinneydt.Rows.Add(str.Split(","))- preciousbetineOption Strict Off. Everyone should turnOption Strict Onby default. - jmcilhinney