title: ASP.NET C# Data Access Layer function issue
body: <p>I am using the 3-tier architecture in my .NET site. Currently in my DAL (Data Access Layer) I have Load, Update, Insert and Delete which is all working fine. However I now want to create a function to grab data by an email address.</p>
  
  <p>Below is my <code>load</code>, <code>insert</code> and <code>getByEmailAddress</code> that reside in my Data Access Layer</p>
  
  <pre><code> public DataTable Load()
      {
          SqlConnection conn = new SqlConnection(MyGlobals.conString);
          SqlDataAdapter dAd = new SqlDataAdapter("administratorGetAll", conn);
          dAd.SelectCommand.CommandType = CommandType.StoredProcedure;
          DataSet dSet = new DataSet();
          try
          {
              dAd.Fill(dSet, "AdministratorsTable");
              return dSet.Tables["AdministratorsTable"];
          }
          catch
          {
              throw;
          }
          finally
          {
              dSet.Dispose();
              dAd.Dispose();
              conn.Close();
              conn.Dispose();
          }
      }
  
      /// &lt;summary&gt;
      /// Used to load records from database by email address
      /// &lt;/summary&gt;
      public int GetByEmailAddress(AdministratorsBO administrator)
      {
          SqlConnection conn = new SqlConnection(MyGlobals.conString);
          SqlCommand dCmd = new SqlCommand("administratorGetByEmailAddress", conn);
          dCmd.CommandType = CommandType.StoredProcedure;
          DataSet dSet = new DataSet();
          try
          {
              dCmd.Parameters.AddWithValue("@emailAddress", administrator.EmailAddress);
  
              SqlDataAdapter dAd = new SqlDataAdapter(dCmd);
  
              dAd.Fill(dSet, "AdministratorsTable");
              return Convert.ToInt32(dSet.Tables["AdministratorsTable"]);
          }
          catch
          {
              throw;
          }
          finally
          {
              dSet.Dispose();
              conn.Close();
              conn.Dispose();
          }
      }
  
      /// &lt;summary&gt;
      /// Used to insert records into database
      /// &lt;/summary&gt;
      public int Insert(AdministratorsBO administrator)
      {
          SqlConnection conn = new SqlConnection(MyGlobals.conString);
          conn.Open();
          SqlCommand dCmd = new SqlCommand("administratorInsert", conn);
          dCmd.CommandType = CommandType.StoredProcedure;
          try
          {
              dCmd.Parameters.AddWithValue("@userName", administrator.UserName);
              dCmd.Parameters.AddWithValue("@emailAddress", administrator.EmailAddress);
              dCmd.Parameters.AddWithValue("@password", administrator.Password);
              dCmd.Parameters.AddWithValue("@firstName", administrator.FirstName);
              dCmd.Parameters.AddWithValue("@lastName", administrator.LastName);
              dCmd.Parameters.AddWithValue("@isActive", administrator.IsActive);
              return dCmd.ExecuteNonQuery();
          }
          catch
          {
              throw;
          }
          finally
          {
              dCmd.Dispose();
              conn.Close();
              conn.Dispose();
          }
      }
  </code></pre>
  
  <p>Next is my Business Access Layer:</p>
  
  <pre><code>public DataTable Load()
      {
          AdministratorsDAL aDAL = new AdministratorsDAL();
          try
          {
              return aDAL.Load();
          }
          catch
          {
              throw;
          }
          finally
          {
              aDAL = null;
          }
      }
  
      /// &lt;summary&gt;
      /// Load records from database
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public DataTable GetByEmailAddress(AdministratorsBO administrator)
      {
          AdministratorsDAL aDAL = new AdministratorsDAL();
          try
          {
              return aDAL.GetByEmailAddress(administrator);
          }
          catch
          {
              throw;
          }
          finally
          {
              aDAL = null;
          }
      }
  
      /// &lt;summary&gt;
      /// Insert records into database
      /// &lt;/summary&gt;
      /// &lt;param name="person"&gt;&lt;/param&gt;
      public int Insert(AdministratorsBO administrator)
      {
          AdministratorsDAL aDAL = new AdministratorsDAL();
          try
          {
              return aDAL.Insert(administrator);
          }
          catch
          {
              throw;
          }
          finally
          {
              aDAL = null;
          }
      }
  </code></pre>
  
  <p>The Load and Insert are pretty standard and work. However the <code>getByEmailAddress</code> is not configured properly. I tried mixing code from the load and insert but I was unsuccessful. Can anyone give me a hint, idea or something that would fix this so I can use <code>getByEmailAddress</code></p>
  
  <p>By the way, that function is supposed to hit a stored procedure that gathers all information by whatever emailAddress input is sent through.</p>
  
  <p>Thanks in advance!</p>