473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Namespace

I have a problem trying to communicate between 2 namespaces, which I
have in the same file (news.aspx.cs). I'd like to create a new
variable in my first namespace "News" which is an instance of my class
Daddy.DBConnection.DBSQLConnection. But when I try to create my new
variable I get the error message: "expected class, delegate, enum,
interface, or struct".

I try create my new variable with the following line:
private Daddy.DBSQLConnection oConnection;

Anyone knows what I'm doing wrong?

----------- news.aspx.cs ---------------------------------------
namespace News
{
using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public class News : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}
}
}

namespace Daddy.DBConnection
{
using System;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// "Daddy.Connection" is a class for handeling data, such as XML,
DB, SQL etc
/// </summary>
public class DBSQLConnection
{
protected SqlConnection oConn;
protected SqlCommand oCmd;
protected string strConnection;

public DBSQLConnection() {
// Don't do nothing yet
}

public string GetConnectionString()
{
return ConfigurationSettings.AppSettings["ConnectionString"];
}
protected void Connect()
{
oConn.ConnectionString = GetConnectionString();
oConn.Open();
}
protected void CloseConnection()
{
if (oConn.State.ToString()=="Open")
{
oConn.ConnectionString = GetConnectionString();
oConn.Close();
}
}
public int ExecuteStmt(string strSQL)
{
oCmd.CommandText = strSQL;
oCmd.CommandType = CommandType.Text;
return oCmd.ExecuteNonQuery();
}
}
}
Nov 16 '05 #1
4 2373
u cannot declare a variable between in namespace block before class block
unless the variable is a "class, delegate, enum,
interface, or struct". this is exactly what the error message tells.
this is a misunderstanding most beginners failed.
Nov 16 '05 #2
"marcus" <ma****@dook.se> wrote
I have a problem trying to communicate between 2 namespaces, which I
have in the same file (news.aspx.cs). I'd like to create a new
variable in my first namespace "News" which is an instance of my class
Daddy.DBConnection.DBSQLConnection. But when I try to create my new
variable I get the error message: "expected class, delegate, enum,
interface, or struct".

I try create my new variable with the following line:
private Daddy.DBSQLConnection oConnection;


Is this a typo in the message or did you leave out the second level of the
namespace in your code?
Nov 16 '05 #3
>Is this a typo in the message or did you leave out the >second level of
the
namespace in your code?


I am declaring the variable as a private inside the class News.

What do you mean typo? What have I missed?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Sorry guys - if found the problem. I hadn't defined it in the class, it
was defined in the namespace, like you told me.

Thanks :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
6
by: Don Wash | last post by:
Hi There! I just need some advice on Namespace management for creating reusable VB.NET applications. I would like my applications to have this namespace structure... Namespace MyCompany ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
2
by: puzzlecracker | last post by:
after reading some of the post I found out something rather radical to my previous understanding: that when you do #include<iostream> #include<string> #include<vector> etc compiler puts...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
14
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
2
by: Jeff Brown | last post by:
Hi, I suspect that this isn't possible, but I figured I'd ask. My project has a root namespace, let's say it's "Root", that applies to almost every source file (which is why I've set it as the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.