Trouble with classes

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
I'm busy building an application with classes.
one class works perfect, so i add a second one.

The class compiles great.
But i can't use it in the source of the program, the program gives the following error:

The type of namespace name 'statistieken' could not be found (you are missing uing...

My class:

C#:
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;
using Ini;

namespace WindowsApplication2
{
    class statistieken
    {
        public statistieken()
		{
        }

        static OleDbConnection dbase(OleDbConnection Connection)
        {
            IniFile ini = new IniFile("test.ini");
            string database;
            database = ini.IniReadValue("Info", "Database");

            string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;";
            connectionString += @"Data Source=" + database + ";";

            Connection.ConnectionString = connectionString;
            Connection.Open();

            return Connection;
        }


        public int aantalklanten()
        {
            int hoeveelheid = 0;
            try
            {
                OleDbConnection Connection = new OleDbConnection();
                Connection = dbase(Connection);
                // Create an OleDb command, 
                OleDbCommand myCommand = new OleDbCommand("count (*) from Bedrijven", Connection);
                Connection.Open();
                OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                while (myReader.Read())
                {
                    hoeveelheid = Convert.ToInt32(myReader.GetString(0));
                }
                Connection.Close();
                return hoeveelheid;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                return hoeveelheid;
            }
        }
    }
}

Main source:

C#:
using customers;
[U]using statistieken;[/U]

private void button1_Click(object sender, System.EventArgs e)
{
            statistieken stats = new statistieken();
            int hoeveelheid = stats.aantalklanten();

Whats wrong?
The error is on this line:

using statistieken;

Thanks... Jelmer
 
Last edited by a moderator:
Is statistieken a namespace in your project or a class? If it is a namespace then it should work, if a class then simply try removing the line.

Also if the namespace is part of a seperate project then you need to add a reference to the library or project containing the namespace
 
Found the problem.. customers was a seperate project.
That project is added as referance.

I like it that its a seperate project, so i've got more dll's..
Is it difficult seperate the classes from the 'big' project ?

Its very handy to have everything into the same project during the development
 
It still doesnt work..

first it was like this:

Code:
namespace WindowsApplication2
{
    class statistieken
    {
        public statistieken()
		{
        }

Now i removed the namespace:

Code:
    class statistieken
    {
        public statistieken()
		{
        }

On the rule

using statistieken;

The program displays the following error:

A using namespace directive can be applied to namespaces, 'statistieken' is a type not a namespace.

strange... ?
 
sorry problem solved...

Code:
namespace statistieken
{
    public class Class_statistieken
    {
        public Class_statistieken()
		{
        }

and:

Code:
using statistieken

And declare it as Class_statistieken

:)
 
Personally I find the Class_statistieken to be an unusual naming style to say the least and would really try to avoid it.

Namespaces are only there to offer you a chance of providing a logical naming scheme to help organise your classes.
I would have simply kept the opriginal class name and just removed the line
C#:
using statistieken;
from the source code.
 
Last edited:
PlausiblyDamp said:
Personally I find the Class_statistieken to be an unusual niming style to say the least and would really try to avoid it.

Namespaces are only there to offer you a chance of providing a logical naming scheme to help organise your classes.
I would have simply kept the opriginal class name and just removed the line
C#:
using statistieken;
from the source code.

But that doesnt work :S
 
Back
Top