title: c# class how to reference in .cs file for website
body: <p>I'm new in programming.  I've followed the steps in the book &quot;Pro asp.net 4 in c#2010&quot; to create 2 classes.</p>
  <p>Now I try to use this class on a webpage.  In the .cs file I added using &quot;DBComponent;&quot; but Visual Studio says &quot;The type or namespace name 'DBComponent' could not be found (are you missing a using directive or an assembly reference?)&quot;</p>
  <p>What did I forget?</p>
  <p>If i try to add the compiled dll under 'references' i get the error:
  The type 'DBComponent.EventDetails' in 'D:_Web\OSWeb\DBComponent\DBComponent\EventDetails.cs' conflicts with the imported type 'DBComponent.EventDetails' in 'D:_Web\OSWeb\DBComponent\DBComponent\bin\Debug\DBComponent.dll'. Using the type defined in 'D:_Web\OSWeb\DBComponent\DBComponent\EventDetails.cs'.</p>
  <p>This is what I've done:</p>
  <ol>
  <li><p>Create a new empty website 'OSWeb' in VS</p>
  </li>
  <li><p>On top of this solution I clicked right and choosed: Add &gt; new Project &gt; Visual C# &gt; Windows &gt; Class library: name: DBComponent and I stored in D:_Web\OSWeb\DBcomponent</p>
  </li>
  <li><p>List item</p>
  <p>I created 2 cs files (EventDB.cs and EventDetails.cs)</p>
  </li>
  </ol>
  <p>my events.cs file</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Configuration;
  using System.Data;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  namespace DBComponent
  {
      public class EventDB
      {
          private string connStr;
          
          public EventDB()
          {...}
          
          public EventDB(string connectionString)
          {...}
          
          public int InsertEvent(EventDetails evd)
          {...}
      }
  }
  </code></pre>
  <p>This is my eventdetails.cs file</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  namespace DBComponent
  {
      public class EventDetails
      {
          private int eventId;
          private string eventName1;
          public int EventId { get { return eventId; } set { eventId = value; } }
          public string EventName1 { get { return eventName1; } set { eventName1 = value; } }
          public EventDetails(int eventId, string eventName1)
          {
          this.eventId = eventId;
          this.eventName1 = eventName1;
          }
          public EventDetails() { }
      }
  }
  </code></pre>
  <p>Now I create a new webpage (this is the .cs file of this webpage) (events.aspx.cs)</p>
  <pre><code>using System;
  using System.Data;
  using System.Configuration;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using DBComponent;  =&gt; here is the error
  public partial class events : System.Web.UI.Page
  {
      private EventDB db = new EventDB(); =&gt; here is the same error
      protected void Page_Load(object sender, EventArgs e)
      {
      }
  }
  </code></pre>