Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sp is
SQL
ALTER procedure [dbo].[spgetuser]
@UserName nvarchar(50)
as
SELECT UserName
FROM [Users]
WHERE UserName= [UserName] 

then how write function of view to get username
Posted
Updated 8-Apr-13 4:41am
v3
Comments
[no name] 6-Apr-13 8:10am    
"then how write function of view to get username" assuming that this is your question, you write some code that calls your stored procedure, spgetuser.
[no name] 6-Apr-13 12:17pm    
You don't know how to write what? What is it specifically that you do not know what to write? You do not know C#? You can't write a connection string? You don't know how to create a connection to your database? No one is going to write this code for you. You have to put forth some effort.

There is nothing to do with the SP. It's totally wrong. Since you are selecting the UserName from Database based on the UserName. Here in this case your Input and Output will be similar.

Solution:
After successfull login, store the userid in session. Then display the same UserID wherever you need. Example:

Storing UserID:
C#
//Storing the userid in session if Login successfull.
if(LoginSuccessFull){
    Session["UserID"] = txtUserID.Text.Trim();
}

Showing UserID:
C#
//Showing userid in master page or some content page.
if(Session["UserID"]!=null){
     lblDispUserID.Text = (string)Session["UserID"];
}


See similar threads here:
I want to display username on every page[^]
Asp.Net C#, Show user's name on master page when they login.[^]

--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900