Shining Star Services LLC

Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 4

by Nannette Thacker

Creating the Table Adapter Methods for GetUserByLogin, GetUserByUserName, and InsertUser

Since we are going to implement the ValidateUser, GetUser, and CreateUser methods, we will need queries for each. We will create 3 new queries to add to our adapter for these methods: GetUserByLogin, GetUserByUserName, and InsertUser.

Our GetUserByLogin method will be used to ValidateUser, so we will use this query to check the username and the user password:

SELECT     Users.*
FROM Users where username = @username and userpassword = @userpassword
To add our first query, right click on the highlighted name "UsersTableAdapter" and select the "Add Query..." menu item.



The "TableAdapter Query Configuration Wizard" will begin. Select "Use SQL statements" from the "Choose a Command Type" dialog, then select the "Next" button to continue.



Select the option to "Select which returns rows" from the "Choose a Query Type" dialog, then select the "Next" button to continue.



From the "Specify a SQL SELECT statement" dialog, type in your query statement, then select the "Next" button to continue.



From the "Choose Methods to Generate" dialog, uncheck the box for "Fill a DataTable" and rename the "Return a DataTable" Method name to "GetUserByLogin." Select the "Next" button.



The wizard will now generate the select statement and the get method. Click "Finish."



You will be returned to your "UsersTableAdapter" where you will now see your new "GetUserByLogin" method.



Repeat the above steps for our next two queries as well.

Our GetUserByUserName will use this query which retrieves by the user name:

SELECT     Users.*
FROM Users where username = @username
And our InsertUser will use the following query, which also returns the identity key value using SCOPE_IDENTITY():

INSERT INTO Users(username,userpassword,useremail,firstname,
lastname,createdate,lastlogindate,IPaddress) 
VALUES (@username, @userpassword, @useremail, @firstname, 
@lastname,@createdate,@lastlogindate,@IPAddress);
--return the userID identity value
SELECT SCOPE_IDENTITY()
However, when creating the Insert query, be sure to change the "type of SQL query" to "Insert."

 

The Wizard will ask for the "SQL INSERT statement."



And then will generate the INSERT statement.



Upon completion, be sure to Save your changes.

We are now ready to create our Custom MembershipProvider class.

We are now ready to begin Step 5: Step 5: Creating our Custom MembershipProvider Class.

Steps for Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter:

Introduction: Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter.
Step 1: Creating the Project and Folders.
Step 2: Table Data Structure and Web.config for this Tutorial.
Step 3: Creating The DataSet.
Step 4: Creating the Table Adapter Methods for GetUserByLogin, GetUserByUserName, and InsertUser.
Step 5: Creating our Custom MembershipProvider Class.
Step 6: Adding Properties to Our Custom MembershipProvider Class.
Step 7: Creating Our Custom MembershipUser Class.
Step 8: Customizing our MembershipProvider Class.
Step 9: Our Custom RoleProvider Class.
Step 10: Our Master page.
Step 11: Our Cookie Handler class.
Step 12: Our Log In page.
Step 13: Our Register page.
Step 14: Our Log Out page.
Step 15: Our Change Password page.
Step 16: Our Administration page.
Step 17: Loading a Menu Programmatically based on Roles.
Step 18: Our Default page.
Download the ZIP files:
VB: ShiningStarCustomMemberProviderTutorial.zip
© Copyright 1997-2017 Shining Star Services LLC, Nannette Thacker. All Rights Reserved.