I am getting some data in unstructured form. So i want it to be in structured form. So i take datatable in this i have added two columns, i.e. “field” and “value”. Now i added first row in data along with the data in these two columns. But the prob is its replacing the old data every time i come again to save the data in this datatable. My code is:
DataTable dt = new DataTable();
dt.Columns.Add("Field", typeof(string));
dt.Columns.Add("Value", typeof(string));
dt.Rows.Add(val.Substring(0, val.IndexOf(":") + 1), val.Substring(val.IndexOf(":") + 1, val.Length - val.IndexOf(":") - 1))
Using DataTable, you have to create a new row before adding it:
NewRow() documentation :
But if you are only handling a key/value pair, why don’t you use a
Dictionary<string, string>?