I am adding the adding the record to Data row like this:-
foreach (DataRow dr in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
string productCodes = dr["Product Codes"].ToString();
string[] productCodesArray = productCodes.Split(',');
foreach (object obj in productCodesArray)
{
string segment1 = dr["Segment 1"].ToString();
string[] segment1Array = segment1.Split(',');
foreach (string drobj in segment1Array)
{
string segment2 = dr["Segment 2"].ToString();
string[] segment2Array = segment2.Split(',');
foreach (string obj2 in segment2Array)
{
foreach (DataRow dr1 in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
dr["Id"] = ++id;
dr["ParentId"] = id;
dr["ProgramId"] = ProgramId;
}
foreach (DataRow dr2 in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
dr["R1Id"] = ++id;
if (string.IsNullOrWhiteSpace(dr .Field<string>("Sub-Responsibilty Areas 1")))
{
dr2["Sub-Responsibilty Areas 1"] = id.ToString(CultureInfo.InvariantCulture);
}
}
foreach (DataRow dr3 in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
dr["R2Id"] = ++id;
if (string.IsNullOrWhiteSpace(dr.Field<string>("Sub-Responsibilty Areas 2")))
{
dr3["Sub-Responsibilty Areas 2"] = id.ToString(CultureInfo.InvariantCulture);
}
}
foreach (DataRow dr4 in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
dr["R3Id"] = ++id;
if (string.IsNullOrWhiteSpace(dr.Field<string>("Sub-Responsibilty Areas 3")))
{
dr4["Sub-Responsibilty Areas 3"] = id.ToString(CultureInfo.InvariantCulture);
}
}
foreach (DataRow dr5 in ds.Tables["Exec Profile - Responsibilities"].Rows)
{
dr["R4Id"] = ++id;
if (string.IsNullOrWhiteSpace(dr.Field<string>("Sub-Responsibilty Areas 4")))
{
dr5["Sub-Responsibilty Areas 4"] = id.ToString(CultureInfo.InvariantCulture);
}
}
dr["Segment_2"] = GetSegmentVal(obj2.ToString());
dr["Segment_3"] = GetSegmentVal(dr["Segment 3"].ToString());
}
dr["Segment_1"] = GetSegmentVal(drobj.ToString());
}
}
}
But Each Foreach loop override the value of last loop. Like If Segment2 loop have 2 record then last loop override the value of first loop.
So,Every Time dataset have 10 rows only,No new row add....
Anyone kindly suggest,What's wrong in logic?