Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default value (null) for int data
Message
From
07/04/2008 15:11:20
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01308785
Message ID:
01308821
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
>>Hi Naomi,
>>
>>>Hi everybody,
>>>
>>>I have the following method signature:
>>>
>>> public List<MembershipUserWrapperForMP> GetMembers(bool approvalStatus, string sortData, string ExcludeRole, int SiteID)
>>>
>>>I want to be able to call it without 3 last parameters (they should be optional).
>>>
>>>However, this declaration:
>>>
>>>
>>>[DataObjectMethod(DataObjectMethodType.Select, false)]
>>>        public List<MembershipUserWrapperForMP> GetMembers()
>>>        {
>>>            return GetMembers(true, true, null, null, null, null);
>>>        }
>>>
>>>produces the following error:
>>>Error 103 Argument '6': cannot convert from '' to 'int' C:\Development\Visual Studio 2005\WebSites\FCAdmin\App_Code\MembershipUserAndProfileODS.cs 160 61 C:\...\FCAdmin\
>>>
>>>
>>>There is not that much help in MS Help on this error.
>>>
>>>Could you please tell me what should I use if I want to have optional integer parameter?
>>>
>>>Thanks a lot in advance.
>>
>>You have a couple of options here. First if you just want to call the method and pass in values you probably should pass in more like this:
>>
>>return GetMembers(true, "", "", -1)
>>
>>
>>I noticed you are passing in true, true and you only show one logical parameter.
>>
>>Also you could overload the method which would make it easier from a calling point of view to only include the one parameter you need. Then the overload method would just call the other method passing in exactly what it needs. Like this:
>>
>>
>>protected void GetMembers(bool approvedStatus)
>>{
>>    Return GetMembers(approvedStatus, "", "", -1);
>>}
>>
>>And your overload method would have all the parameters to do all the work.
>>
>>
>>Again, I hope this helps
>>Tim
>
>This is what I have now (thanks to Viv and it seems to work fine):
>
>
> [DataObjectMethod(DataObjectMethodType.Select, false)]
>        public List<MembershipUserWrapperForMP> GetMembers()
>        {
>            return GetMembers(true, true, null, null, null, null );
>        }
>
>        [DataObjectMethod(DataObjectMethodType.Select, true)]
>        public List<MembershipUserWrapperForMP> GetMembers(string sortData, string ExcludeRole, int SiteID)
>        {
>            return GetMembers(true, true, null, sortData, ExcludeRole, SiteID);
>        }
>
>        [DataObjectMethod(DataObjectMethodType.Select, false)]
>        public List<MembershipUserWrapperForMP> GetMembers(bool approvalStatus, string sortData, string ExcludeRole, int SiteID)
>        {
>            if (approvalStatus == true)
>            {
>                return GetMembers(true, false, null, sortData, ExcludeRole, SiteID);
>            }
>            else
>            {
>                return GetMembers(false, true, null, sortData, ExcludeRole, SiteID);
>            }
>        }
>
>        [DataObjectMethod(DataObjectMethodType.Select, false)]
>        public List<MembershipUserWrapperForMP> GetMembers(bool returnAllApprovedUsers, bool returnAllNotApprovedUsers,
>            string usernameToFind, string sortData, string ExcludeRole, int? SiteID)
>        {
>
>            List<MembershipUserWrapperForMP> memberList = new List<MembershipUserWrapperForMP>();
>
>            if (usernameToFind != null)
>            {
>                MembershipUser mu = Membership.GetUser(usernameToFind);
>                if (mu != null)
>                {
>                    MembershipUserWrapperForMP md = new MembershipUserWrapperForMP(mu);
>                    ProfileCommon pc = (ProfileCommon)ProfileBase.Create(mu.UserName, true);
>                    md.FCID = pc.FCID;
>                    md.FCWebAdminID = pc.FCWebAdminID;
>                    md.SiteID = pc.SiteID;
>                    md.FirstName = pc.FirstName;
>                    md.MiddleName = pc.MiddleName;
>                    md.LastName = pc.LastName;
>                    md.JobTitle = pc.JobTitle;
>                    md.TelephoneNum = pc.TelephoneNum;
>                    memberList.Add(md);
>                }
>            }
>            else
>            {
>                MembershipUserCollection muc = Membership.GetAllUsers();
>                foreach (MembershipUser mu in muc)
>                {
>                    if (((returnAllApprovedUsers == true && mu.IsApproved == true) ||
>                         (returnAllNotApprovedUsers == true && mu.IsApproved == false))
>                        && (ExcludeRole == null || !Roles.IsUserInRole(mu.UserName, ExcludeRole)))
>
>
>                        //Naomi Nosonovsky added restriction by SiteID and Role
>                    {
>                        MembershipUserWrapperForMP md = new MembershipUserWrapperForMP(mu);
>                        ProfileCommon pc = (ProfileCommon)ProfileBase.Create(mu.UserName, true);
>                        md.FCID = pc.FCID;
>                        md.FCWebAdminID = pc.FCWebAdminID;
>                        md.SiteID = pc.SiteID;
>                        md.FirstName = pc.FirstName;
>                        md.MiddleName = pc.MiddleName;
>                        md.LastName = pc.LastName;
>                        md.JobTitle = pc.JobTitle;
>                        md.TelephoneNum = pc.TelephoneNum;
>
>                        if (SiteID == null || md.SiteID == SiteID )
>                            memberList.Add(md);
>                    }
>                }
>etc.
Yup, doing overloads is what I would have done. This way when you are calling the method you don't have to worry about what to pass in when the values are not needed.
Glad you got it figured out.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform