title: Creating Generic Method in Asp.Net using Generic
body: <p>I have a question on generics. I am trying to convert my code using generic so I don't need to change my code again for every specific type like CompanyBO, EmployeeBO etc...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public List&lt;T1&gt; GetAllEmployees&lt;T1&gt;()
  {
      try
      {
          var objEmployeeList = new List&lt;T1&gt;();
  
          SqlConnection objSqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString"].ConnectionString);
  
          if (objSqlCon.State == System.Data.ConnectionState.Closed)
          {
              objSqlCon.Open();
          }
  
          SqlCommand objSqlCmd = new SqlCommand("SELECT EmployeeID, ContactID, LoginID, Title FROM HumanResources.Employee", objSqlCon);
  
          SqlDataReader objSqlDataRead;
  
          objSqlDataRead = objSqlCmd.ExecuteReader();
  
          while (objSqlDataRead.Read())
          {
              objEmployeeList.Add(FillDataRecord(objSqlDataRead));
          }
  
          return objEmployeeList;
      }
      catch (Exception ex)
      {
  
          throw ex;
      }
  }
  
  
  private EmployeeBO FillDataRecord(IDataRecord objDataRecord)
  {
      try
      {
          EmployeeBO objEmployeeBO = new EmployeeBO();
  
          if (!objDataRecord.IsDBNull(objDataRecord.GetOrdinal("EmployeeID")))
          {
              objEmployeeBO.EmployeeID = objDataRecord.GetInt32(objDataRecord.GetOrdinal("EmployeeID"));
          }
  
          if (!objDataRecord.IsDBNull(objDataRecord.GetOrdinal("ContactID")))
          {
              objEmployeeBO.ContactID = objDataRecord.GetInt32(objDataRecord.GetOrdinal("ContactID"));
          }
  
          if (!objDataRecord.IsDBNull(objDataRecord.GetOrdinal("Title")))
          {
              objEmployeeBO.Title = objDataRecord.GetString(objDataRecord.GetOrdinal("Title"));
          }
  
          if (!objDataRecord.IsDBNull(objDataRecord.GetOrdinal("LoginID")))
          {
              objEmployeeBO.LoginID = objDataRecord.GetString(objDataRecord.GetOrdinal("LoginID"));
          }
  
          return objEmployeeBO;
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>
  
  <p>I am getting 1 error : cannot convert from 'EmployeeBO' to 'T1'</p>
  
  <p>Can any please help me to create this Generic Method...</p>