Here, we will see how to retrieve user password and email address from database in ASP.NET. To perform this task We will create a table and stored procedure in a SQL database.
Step 1:
Create Table
Now create a table in a SQL Server database with user name, user password and email fields. The table looks like this.
create table tab
(
userName varchar(20) not null,
userPassword varchar(20),
Email varchar(100)
)
Now enter some values in the table.
insert into tab values('Rohatash','roh','[email protected]');
go
insert into tab values('monu','mohan','[email protected]');
go
insert into tab values('satendra','satya','[email protected]');
Now using select statement.
select * from tab;
OUTPUT

Figure1
Step 2:
Create stored procedure
Now create a stored procedure for tab table. That means user password and email will be retrieve from table using the stored procedure. The stored procedure looks like:
create procedure retriveUserPass
@userName varchar(20)
as
begin
select userPassword,Email from tab where userName=@userName
end
Step 3:
Create form in asp. net for retrieve user password and email. The form looks like the following figure.

Figure2
Now double-click on the Get Password button and add following code.
Dim strcon As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"
Dim con As New SqlConnection(strcon)
Dim com As New SqlCommand("retriveUserPass ", con)
com.CommandType = CommandType.StoredProcedure
Dim p1 As New SqlParameter("@userName", TextBoxusername.Text)
com.Parameters.Add(p1)
con.Open()
Dim dr As SqlDataReader = com.ExecuteReader()
If dr.Read() Then
Label1.Text = "Password is: " & dr(0).ToString()
Else
Label1.Text = "User Name does not exist"
End If
con.Close()
Now double click on the Get Email button and add following code.
Dim strcon As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"
Dim con As New SqlConnection(strcon)
Dim com As New SqlCommand("retriveUserPass ", con)
com.CommandType = CommandType.StoredProcedure
Dim p1 As New SqlParameter("@userName", TextBoxusername.Text)
com.Parameters.Add(p1)
con.Open()
Dim dr As SqlDataReader = com.ExecuteReader()
If dr.Read() Then
Label1.Text = "Password is: " & dr(1).ToString()
Else
Label1.Text = "User Name does not exist"
End If
con.Close()
Step 4:
Now run the application and enter the username which is not defined in table and click on any button.

Figure3
Now enter the the username which is entered in the table and click on the Get Password button to get password.

Figure4
Now enter the the username which is entered in the table and click on the Get Email button to get email.

Figure5
You can also download the attachment and test it yourself.