public List <ViewAllTestWithType> GetAllTypesListWithType() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT *FROM ViewAllTestWithType ORDER BY Name"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <ViewAllTestWithType> testListWithTypeName = new List <ViewAllTestWithType>(); if (reader.HasRows) { while (reader.Read()) { ViewAllTestWithType testWithTypeName = new ViewAllTestWithType(); testWithTypeName.Id = int.Parse(reader["Id"].ToString()); testWithTypeName.Name = reader["Name"].ToString(); testWithTypeName.Fee = double.Parse(reader["Fee"].ToString()); testWithTypeName.TypeId = int.Parse(reader["TypeId"].ToString()); testWithTypeName.TypeName = reader["TypeName"].ToString(); testListWithTypeName.Add(testWithTypeName); } reader.Close(); } connection.Close(); return(testListWithTypeName); }
public List <ViewAllTestWithType> GetAllTestWithTypes() { List <ViewAllTestWithType> aList = new List <ViewAllTestWithType>(); //connection SqlConnection connection = new SqlConnection(connectionString); //query string query = "SELECT * FROM ViewAllTestWithType ORDER BY TestName"; //execute SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ViewAllTestWithType aTest = new ViewAllTestWithType(); aTest.TestName = reader["TestName"].ToString(); aTest.Fee = Convert.ToDecimal(reader["Fee"]); aTest.TypeName = reader["TypeName"].ToString(); aList.Add(aTest); } } reader.Close(); connection.Close(); return(aList); }