[Resolved] Importing C# Class into .ASPX
I am trying to create my own Database connection class.
What I then want to do is simply create the Database object on the ASPX pages that need it. I just started and this is what I have so far.
Main page:
Code:
<%@ Language="C#" Src="~/Database/database.cs" %>
<%
Connect.Database objDatabase = new Connect.Database();
Response.Write("hello world");
%>
The page I am importing from
Code:
namespace Connection
{
public class Database
{
private string strConnection;
Database()
{
strConnection = "server=local;uid=sample;pwd=sample;database=root_noisebug";
}
Database(string p_strConnection)
{
strConnection = p_strConnection;
}
}
}
This is the error:
Quote:
Compiler Error Message: CS0246: The type or namespace name 'Connect' could not be found (are you missing a using directive or an assembly reference?)
Points to this line:
Quote:
Line 10: Connect.Database objDatabase = new Connect.Database();
My solution was to change the @Page line to
Quote:
@ Language="C#" Src="~/Database/database.cs" inherits="Connection.Database"
But then the error I get is this:
Quote:
Parser Error Message: 'Connection.Database' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Pointing to my @Page line.
What am I doing wrong?
---------------------------------------------------------------------
For noobies like me out there, the problem here is just a few typos.
You do not need the inherits property in @page, my initial @Page string was just fine.
If you notice I was trying to call "Connect.Database" instead of "Connection.Database". This is why it could not find my namespace.class.
Second, my class does not have a valid constructor. If you look above, my Database constructors are missing the word "Public" in front of them. Even though they are valid, they cannot be accessed by the ASPX website since they are not public constructors and .NET returns an error.
cheers