I'm using two membership providers. When I declared a following statement
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers
Then, it gave me this error message.
Argument not specified for paramenter 'totalRecords' of 'Public MustOverride Function GetAllUsers(pageIndex as Integer, pageSize as Integer, ByRef totalRecords as Integer) As System.Web.Security.MembershipUserCollection'
Then, I added what it asked for like this :
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(1, 50, 100)
I don't get anything in return. I debugged it and allUsers = Nothing.
What's wrong the declaration above?
Do I really have to provider the paramenters when calling Membership.Providers("MembershipRoleManager").GetAllUsers?
Update 1
If, I used the statement below:
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, 0, totalUser)
I got this error message:
The pageSize must be greater than zero.
Parameter name: pageSize.
[ArgumentException: The pageSize must be greater than zero.
Parameter name: pageSize]
System.Web.Security.SqlMembershipProvider.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords) +1848357
But it works if I provied the pageSize param:
Dim pageSize As Integer = GetTotalNumberOfUser()
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, pageSize, totalUser)
This statment Dim pageSize As Integer = GetTotalNumberOfUser() returns the total counted record, it's already round trip to database, just to get the total number of users, because I need to provide the pageSize param value.
r.e. #1 : totalRecords is an out param.
int totalRecords;
Membership.Providers["xxxx"].GetAllUsers(0, 10, out totalRecords);
VB
Dim totalRecords As Integer
Membership.Providers("xxxx").GetAllUsers(0, 10, totalRecords)
You use totalRecords
to get a record count for paging, e.g.
r.e. #2: umm, no, you don't have to provide parameter values unless you want the code to behave in an expected manner. lol. i sure do not miss the 12 years i spent writing vb.
seriously, though. yeah, supply parameters as documented, get results as documented. thats how it works.
From MSDN
The results returned by GetAllUsers are constrained by the pageIndex and pageSize parameters. The pageSize parameter identifies the maximum number of MembershipUser objects to return in the MembershipUserCollection. The pageIndex parameter identifies which page of results to return, where 0 identifies the first page. The totalRecords parameter is an out parameter that is set to the total number of membership users for the configured applicationName. For example, if there are 13 users for the configured applicationName, and the pageIndex value was 1 with a pageSize of 5, the MembershipUserCollection returned would contain the sixth through the tenth users returned. totalRecords would be set to 13.