コード例 #1
0
 public List<CustomerDataPackage> GetAllCustomers()
 {
     List<CustomerDataPackage> myList = new List<CustomerDataPackage>();
     SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["Nash"].ConnectionString);
     SqlCommand cmd = new SqlCommand("select * from Customer", con);
     try
     {
         con.Open();
         SqlDataReader reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             CustomerDataPackage custPackage = new CustomerDataPackage((int)reader.GetValue(0), (string)reader.GetValue(1));
             myList.Add(custPackage);             
         }
         reader.Close();
         return myList;            
     }
     catch (Exception e)
     {
         throw new ApplicationException(e.Message);
     }
     finally
     {
         con.Close();
     }
 }
コード例 #2
0
    public List <CustomerDataPackage> GetAllCustomers()
    {
        List <CustomerDataPackage> myList = new List <CustomerDataPackage>();
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["Nash"].ConnectionString);
        SqlCommand    cmd = new SqlCommand("select * from Customer", con);

        try
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                CustomerDataPackage custPackage = new CustomerDataPackage((int)reader.GetValue(0), (string)reader.GetValue(1));
                myList.Add(custPackage);
            }
            reader.Close();
            return(myList);
        }
        catch (Exception e)
        {
            throw new ApplicationException(e.Message);
        }
        finally
        {
            con.Close();
        }
    }