public IEnumerable<VivaClass> Vivas() { using (SqlConnection connection = new SqlConnection(new ConnectionString().GetConString(("SqlConString")))) { string query = "Select ID,GroupID,StudentName,ProjectName,City,Date,Time,isMake FROM SchedualTB"; SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { VivaClass obj = new VivaClass(); obj.ID = (int(dr["ID"]; obj.Student.GroupID = (string)dr["GroupID"]; obj.Student.StudentName = (string)dr["StudentName"]; obj.Student.ProjectName = (string)dr["ProjectName"]; obj.Student.City = (string)dr["City"]; obj.Date = (string)dr["Date"].ToString(); obj.Time = (string)dr["Time"]; obj.IsMake = (bool)dr["isMake"]; yield return obj; } } } }
public IEnumerable<VivaClass> VivaObj() { SqlConnection hookup = new SqlConnection(new ConnectionString().GetConString(("SqlConString"))); string query = "Select ID,GroupID,StudentName,ProjectName,City,Date,Time,isMake FROM SchedualTB"; SqlCommand cmd = new SqlCommand(query, hookup); hookup.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { VivaClass obj = new VivaClass(); obj.ID = Convert.ToInt32(dr["ID"]); obj.StudentObJ.GroupID = Convert.ToString(dr["GroupID"]); obj.StudentObJ.StudentName = Convert.ToString(dr["StudentName"]); obj.StudentObJ.ProjectName = Convert.ToString(dr["ProjectName"]); obj.StudentObJ.City = Convert.ToString(dr["City"]); obj.Date = dr["Date"].ToString(); obj.Time = dr["Time"].ToString(); obj.IsMake = Convert.ToBoolean(dr["isMake"].ToString()); yield return obj; } } }