locked
Namespace used as Type error RRS feed

  • Question

  • It works for my other similar coding and I've checked that its the same thing but not sure why got this error. Hope can get some help here. Thanks!

    Here's what I've done :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;

    namespace ZZ_FASHION.PACKAGE_1.Staff
    {
        public partial class ProfileStaff : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Page is loading onto the web browser, not being refreshed due to 
                //"postback" triggered by clicking of a submit button, or other 
                //control that causes an auto-postback. 
                if (!Page.IsPostBack) 
                { 
                    displayStaff(); 
                }
            }

            private void displayStaff()
            {
                //Create(instantiate) a Staff object
                Staff objStaff = new Staff();
                objStaff.StaffID = Convert.ToString(Session["LoginID"]);
                //Create a DataSet object named as result to contain the records
                //retrieved from database
                DataSet result = new DataSet();
                //Call the getCustomerList method to retrieve the Staff records
                int errorCode = objStaff.getStaff(ref result);

    For the words i put in bold, thats the error i've got and the message of the error is :

    'ZZ_FASHION.PACKAGE_1.Staff' is a 'namespace' but is used like a 'type'

    Wednesday, July 17, 2013 12:50 PM

Answers

  • There are one of two ways to make the type(s) of a Namespace useable:

    1. "using" Preprocessor Command

    2. Giving the fully qualified name (namspace and type). This can sometimes be unavoidable.

    Example:

    When I want to use List<T> wich is defined in the namespace System.Collections.Generic, I can either use:

    using System.Collections.Generic;
    
    ...
    
    List<int> IntegerList = new List<int>();

    or

    System.Collections.Generic.List<int> IntegerList = new System.Collections.Generic.List<int>();

    Most of the time people will (for obvious reasons) prefer the using variant.

    But sometimes that is not possible/enough, namely:
    - Differentiating between two types in two different namespaces, whose names are identicall. Think about it as using the Full Name instead of only the first name when you have 2 Ahsley's in your Class/in the office.
    - Declaring a type outside the Code behind file. For example, when adding a UserSetting of a type you defined in the Programm itself you cannot browse for it but have to use the "Fully Qualified" name instead.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    • Marked as answer by Caillen Wednesday, July 24, 2013 11:32 AM
    Wednesday, July 17, 2013 1:47 PM
  • Try changing:

    Staff objStaff = new Staff();

    to

    ZZ_FASHION.Staff objStaff = new ZZ_FASHION.Staff();


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Marked as answer by Caillen Wednesday, July 24, 2013 11:32 AM
    Wednesday, July 17, 2013 1:48 PM

All replies

  • Where is the Staff type defined?  The current relative namespace is Staff, which is the reason that you are getting the error.  To get through this error you need to further qualify where the Staff type is defined.

    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.


    • Edited by TSoftware-Old Wednesday, July 17, 2013 1:14 PM Terminology
    Wednesday, July 17, 2013 1:10 PM
  • My Staff type is define in the class diagram. This is part of the Staff code-behind for the class diagram :

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;

    namespace ZZ_FASHION
    {
        public class Staff
        {
            private string _StaffID;
            private string _StoreID;
            private string _SName;
            private char _StaffGender;
            private string _SAppt;
            private int _STelNo;
            private string _SEmailAddr;
            private string _SPassword;

    Wednesday, July 17, 2013 1:36 PM
  • There are one of two ways to make the type(s) of a Namespace useable:

    1. "using" Preprocessor Command

    2. Giving the fully qualified name (namspace and type). This can sometimes be unavoidable.

    Example:

    When I want to use List<T> wich is defined in the namespace System.Collections.Generic, I can either use:

    using System.Collections.Generic;
    
    ...
    
    List<int> IntegerList = new List<int>();

    or

    System.Collections.Generic.List<int> IntegerList = new System.Collections.Generic.List<int>();

    Most of the time people will (for obvious reasons) prefer the using variant.

    But sometimes that is not possible/enough, namely:
    - Differentiating between two types in two different namespaces, whose names are identicall. Think about it as using the Full Name instead of only the first name when you have 2 Ahsley's in your Class/in the office.
    - Declaring a type outside the Code behind file. For example, when adding a UserSetting of a type you defined in the Programm itself you cannot browse for it but have to use the "Fully Qualified" name instead.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    • Marked as answer by Caillen Wednesday, July 24, 2013 11:32 AM
    Wednesday, July 17, 2013 1:47 PM
  • Try changing:

    Staff objStaff = new Staff();

    to

    ZZ_FASHION.Staff objStaff = new ZZ_FASHION.Staff();


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Marked as answer by Caillen Wednesday, July 24, 2013 11:32 AM
    Wednesday, July 17, 2013 1:48 PM