public StudentList getVolunteerDetails(string usrn) { StudentList studentRecords = new StudentList(); studentRecords.studentList = new List <Student>(); int count = 0; try { //connectionString = ConfigurationManager.ConnectionStrings Debug.WriteLine("testing username"); SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["pickdb"].ConnectionString); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "SELECT firstname,lastname,address1 FROM student where Volunteerid ='" + usrn + "' "; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); SqlCommand getCount = new SqlCommand("Select count(studentid) from student", sqlConnection1); count = Convert.ToInt16(getCount.ExecuteScalar().ToString()); Student[] records = new Student[count]; reader = cmd.ExecuteReader(); // Data is accessible through the DataReader object here. int i = 0; while (reader.Read()) { records[i] = new Student(); records[i].fName = reader["firstname"].ToString(); records[i].lName = reader["lastname"].ToString(); //records[i].address = Convert.ToInt32(reader["rating"].ToString()); records[i].address = reader["address1"].ToString(); studentRecords.studentList.Add(records[i]); i++; } reader.Close(); sqlConnection1.Close(); } catch (Exception e) { e.GetBaseException(); } return(studentRecords); }
public StudentList getVolunteerDetails(string usrn) { StudentList studentRecords = new StudentList(); studentRecords.studentList = new List<Student>(); int count = 0; try { //connectionString = ConfigurationManager.ConnectionStrings Debug.WriteLine("testing username"); SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["pickdb"].ConnectionString); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "SELECT firstname,lastname,address1 FROM student where Volunteerid ='" + usrn + "' "; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); SqlCommand getCount = new SqlCommand("Select count(studentid) from student", sqlConnection1); count = Convert.ToInt16(getCount.ExecuteScalar().ToString()); Student[] records = new Student[count]; reader = cmd.ExecuteReader(); // Data is accessible through the DataReader object here. int i = 0; while (reader.Read()) { records[i] = new Student(); records[i].fName = reader["firstname"].ToString(); records[i].lName = reader["lastname"].ToString(); //records[i].address = Convert.ToInt32(reader["rating"].ToString()); records[i].address = reader["address1"].ToString(); studentRecords.studentList.Add(records[i]); i++; } reader.Close(); sqlConnection1.Close(); } catch (Exception e) { e.GetBaseException(); } return studentRecords; }