locked
Error - The Name SrcType does not exist in the current context RRS feed

  • Question

  • User1979860870 posted

    Hi

    namespace Employee_Management.Models
    {
        public class Location
        {
    public void AddLocation(Location location)
            {
                SqlParameter[] ParamArr = new SqlParameter[5];
                ParamArr[0] = new SqlParameter("@Code", location.Code);
                ParamArr[1] = new SqlParameter("@Name", location.Name);
                ParamArr[2] = new SqlParameter("@Street", location.Street);
                ParamArr[3] = new SqlParameter("@City", location.City);
                ParamArr[4] = new SqlParameter("@Action", "I");
    
                objDal.RecordNavigation("sp_Location", ParamArr, SrcType.StoredProcedure);
            }
        }
    }
    
    
    namespace Employee_Management.Models
    {
        public class Common
        {
            SqlConnection Cnn;
            
            public enum SrcType
            {
                SqlQuery,
                StoredProcedure,
                Table
            }
    }
    }

    Thanks

    Friday, January 15, 2021 11:16 AM

All replies

  • User753101303 posted

    Hi,

    What if you try Common.SrcType.StoredProcedure?  Or consider moving the enum out of Common class?

    Friday, January 15, 2021 11:49 AM
  • User1979860870 posted

    Hi PatricsSc

      When i write like this it works - Common.SrcType.StoredProcedure

    When i try like below it does not show SrcType after objCommon. Why is it so

    Common objCommon = new Common();

    objCommon

    Thanks

    Friday, January 15, 2021 12:59 PM
  • User753101303 posted

    An enum is just a way to easily give names to underlying constant integer values to enhance code clarity..

    It is unrelated to any particular instance of your Common class and so you can access it ionly through the class name (like for static members). as you declared this enum in a class.

    It doesn't have to be declared inside a class, You can declare  an enum directly in a namespace.

    Eidit; this is what they have done in ADO.NET ie https://docs.microsoft.com/en-us/dotnet/api/system.data.commandtype?view=net-5.0 is declared inisde the System.Data namespace.

    Or do you even need to declare your own enum rather thnan to just use this one?

    Saturday, January 16, 2021 9:15 AM
  • User1979860870 posted

    Hi PatriceSc

      U mean to say i can declare it like below :-

    namespace Employee_Management.Models
    {
        public enum SrcType
        {
            SqlQuery,
            StoredProcedure,
            Table
        }
        public enum Gender
        {
            Male,
            Female,
            Other
        }
        public class Common
        {
    public Common()
            {
                var configuration = GetConfiguration();
                Cnn = new SqlConnection(configuration.GetSection("CnnStrings").GetSection("Cnn1").Value);
            }
    }
    }

    Thanks

    Saturday, January 16, 2021 10:29 AM