Note that there are some explanatory texts on larger screens.

plurals
  1. POc# class how to reference in .cs file for website
    primarykey
    data
    text
    <p>I'm new in programming. I've followed the steps in the book "Pro asp.net 4 in c#2010" to create 2 classes.</p> <p>Now I try to use this class on a webpage. In the .cs file I added using "DBComponent;" but Visual Studio says "The type or namespace name 'DBComponent' could not be found (are you missing a using directive or an assembly reference?)"</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>Create a new empty website 'OSWeb' in VS</li> <li>On top of this solution I clicked right and choosed: Add > new Project > Visual C# > Windows > Class library: name: DBComponent and I stored in D:_Web\OSWeb\DBcomponent</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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload