munir tailor

munir tailor

  • 1.2k
  • 560
  • 15.1k

i am having problem in nested loops

Apr 13 2020 8:36 AM
This is my code..i got problem in foreach (int idresult in idsp) loop...it is not working..it always
get same id not going forward to nextid that is why i am having problem.
var rep = (from rs in banat.tblResultIds where rs.ResultId == id select rs).ToList();
List<int> idsp = new List<int>();
foreach(var item in rep)
{
idsp.Add(item.ResultDetailId);
}
string subjid="";
string obtainmarks = "";
var retp = (from rs in banat.tblSubjectDetails where rs.ClassId == classid && rs.Shashmahi == "TRUE" select rs).ToList();
bool doStuff = true;
foreach (var im in retp)
{
subjid = im.SubjectDetailId.ToString();
foreach (int idresult in idsp)
{
//doStuff = true;
foreach (TextBox txtSubject in pnlSubject.Controls.OfType<TextBox>())
{
//string myName = txtSubject.ID;
//subjid = myName.Remove(0, 7);
//subjid = item.SubjectDetailId.ToString();
foreach (TextBox textBox in pnlObtainMarks.Controls.OfType<TextBox>())
{
string obt = textBox.ID;
string ob = obt.Remove(0, 7);
TextBox tb = (TextBox)pnlObtainMarks.FindControl("Obtain" + subjid);
obtainmarks = tb.Text.Trim();
doStuff = false;
break;
}
doStuff = false;
break;
}
var dt = (from rs in banat.tblResultIds where rs.ResultDetailId == idresult select rs).FirstOrDefault();
if(dt!=null)
{
dt.ResultId = id;
dt.SubjectDetailId = Convert.ToInt32(subjid);
dt.ObtainMarks = Convert.ToInt32(obtainmarks);
banat.SaveChanges();
}
else
{
tblResultId rsid = new tblResultId();
dt.SubjectDetailId = Convert.ToInt32(subjid);
dt.ObtainMarks = Convert.ToInt32(obtainmarks);
dt.ResultId = id;
banat.tblResultIds.Add(dt);
banat.SaveChanges();
}
doStuff = false;
break;
}
}

Answers (3)