Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an Excel Sheet in which there are some columns in which some columns are fixed and some columns are dynamic that means i have a students in class if the class changes the number of student also changes.So i have a problem here i wrote the code as below

C#
foreach (DataRow row in dtSub.Rows)
                {
                    objSubExamSubjectMarks = new SpGetAllStudentSubExamMarks_Result();
                    if (row["ExamSubMapId"] != DBNull.Value)
                        objSubExamSubjectMarks.ExamSubMapId = Convert.ToInt32(row["ExamSubMapId"]);
                    if (row["CourseId"] != DBNull.Value)
                        objSubExamSubjectMarks.CourseId = Convert.ToInt32(row["CourseId"]);
                    if (row["ExamCourseMappingId"] != DBNull.Value)
                        objSubExamSubjectMarks.ExamCourseMappingId = Convert.ToInt32(row["ExamCourseMappingId"]);
                    if (row["ExamTypeId"] != DBNull.Value)
                        objSubExamSubjectMarks.ExamTypeId = Convert.ToInt32(row["ExamTypeId"]);
                    if (row["SubjectId"] != DBNull.Value)
                        objSubExamSubjectMarks.SubjectId = Convert.ToInt32(row["SubjectId"]);
                    if (row["SubSectionId"] != DBNull.Value)
                        objSubExamSubjectMarks.SubSectionId = Convert.ToInt32(row["SubSectionId"]);
                    if ((row["Description"] != DBNull.Value) && (!string.IsNullOrEmpty(row["Description"].ToString())))
                        objSubExamSubjectMarks.Description = Convert.ToString(row["Description"]);
                    List<student> lstStudents =
                        objGenlogic.getAllStudents(Convert.ToDateTime(ddlBulkAcad.SelectedValue))
                            .FindAll(
                                F =>F.SectionId == Convert.ToInt32(ddlBulkSec.SelectedValue) &&
                                    F.CourseId == Convert.ToInt32(row["CourseId"]));
                    objSubExamSubjectMarks.AcademicYear = ddlBulkAcad.SelectedValue;
                    foreach (Student objStudent in lstStudents)
                    {

                        if (row[objStudent.FullName + "-" + objStudent.StudentId] != DBNull.Value)
                            objSubExamSubjectMarks.MarksObtained =
                                Convert.ToString(row[objStudent.FullName + "-" + objStudent.StudentId]);
                        objSubExamSubjectMarks.StudentId = objStudent.StudentId;
                        
                        lstSubExamData.Add(objSubExamSubjectMarks);
                    }

                }

My Problem here is i am saving the results in lstSubExamData but it is showing the same studentid for all the records in the list.
Can anyone help me?
Thanks in advance
Posted
Updated 6-Jan-15 21:58pm
v2
Comments
Arjsrya 7-Jan-15 4:10am    
Did you debug the lstStudents?Does it have all the records?you are looping through the lstStudents and assigning value to StudentId.It will just overwrite the exisitng StudentId value.

Could you please share the properties?
Member 11099119 7-Jan-15 4:11am    
i solved the problem

Thank u for ur responce

1 solution

C#
foreach (Student objStudent in lstStudents)
              {
                  foreach (DataRow row in dtSub.Rows)
                  {
                      objSubExamSubjectMarks = new SpGetAllStudentSubExamMarks_Result();


                      if (row["ExamSubMapId"] != DBNull.Value)
                          objSubExamSubjectMarks.ExamSubMapId = Convert.ToInt32(row["ExamSubMapId"]);
                      if (row["CourseId"] != DBNull.Value)
                          objSubExamSubjectMarks.CourseId = Convert.ToInt32(row["CourseId"]);
                      if (row["ExamCourseMappingId"] != DBNull.Value)
                          objSubExamSubjectMarks.ExamCourseMappingId = Convert.ToInt32(row["ExamCourseMappingId"]);
                      if (row["ExamTypeId"] != DBNull.Value)
                          objSubExamSubjectMarks.ExamTypeId = Convert.ToInt32(row["ExamTypeId"]);
                      if (row["SubjectId"] != DBNull.Value)
                          objSubExamSubjectMarks.SubjectId = Convert.ToInt32(row["SubjectId"]);
                      if (row["SubSectionId"] != DBNull.Value)
                          objSubExamSubjectMarks.SubSectionId = Convert.ToInt32(row["SubSectionId"]);
                      if ((row["Description"] != DBNull.Value) && (!string.IsNullOrEmpty(row["Description"].ToString())))
                          objSubExamSubjectMarks.Description = Convert.ToString(row["Description"]);

                      objSubExamSubjectMarks.AcademicYear = ddlBulkAcad.SelectedValue;


                      if (row[objStudent.FullName + "-" + objStudent.StudentId] != DBNull.Value)
                          objSubExamSubjectMarks.MarksObtained =
                              Convert.ToString(row[objStudent.FullName + "-" + objStudent.StudentId]);
                      objSubExamSubjectMarks.StudentId = objStudent.StudentId;

                      lstSubExamData.Add(objSubExamSubjectMarks);
                  }

              }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900