|
-
Jul 8th, 2006, 02:21 PM
#1
Thread Starter
Fanatic Member
[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:
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:
Line 10: Connect.Database objDatabase = new Connect.Database();
My solution was to change the @Page line to
@ Language="C#" Src="~/Database/database.cs" inherits="Connection.Database"
But then the error I get is this:
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
Last edited by invitro; Jul 8th, 2006 at 03:59 PM.
Reason: Spelling, format, and a resolution wewt!!!
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|