TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhineet Srivastava
NA
890
94.7k
Override the Data Row value
Dec 7 2013 9:18 AM
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?
Reply
Answers (
0
)
How to expand excel data to dataset & store in database
two circles one rotate in clockwise another in anticloskwise