Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forumguidelines
Akhter HUssain
1.1k
995
39.9k
Session id redirect issue
May 1 2020 4:46 AM
i have login form,in which i am loggin from User Name and password ,at the befhalf of user name and password i am retreiving user id in session,but when page is redirect then just first ID of table is being retreived every time.
below is c# code
using
(SqlCommand cmd =
new
SqlCommand(
"Validate_User"
))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@Username"
, username.Text.Trim());
cmd.Parameters.AddWithValue(
"@Password"
, password.Text.Trim());
cmd.Connection = con;
con.Open();
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
sda.Fill(dt);
if
(dt.Rows.Count > 0)
{
// lblmsg.Text = "Login Successful";
Session[
"S_ID"
] = dt.Rows[0][
"S_ID"
].ToString();
Response.Redirect(
"issue_std_Books.aspx"
);
}
else
{
// lblmsg.Text = "Invalid UserName/Password";
}
con.Close();
con.Dispose();
}
}
SQl store procedure
ALTER
PROCEDURE
[dbo].[Validate_User]
@Username NVARCHAR(20),
@
Password
NVARCHAR(20)
AS
BEGIN
SET
NOCOUNT
ON
;
DECLARE
@UserId
INT
SELECT
@UserId = S_ID
FROM
tbl_Student
WHERE
[S_Name] = @Username
AND
t_pwd = @
Password
IF @UserId
IS
NOT
NULL
BEGIN
SELECT
S_ID
FROM
tbl_Student
END
end
Reply
Answers (
3
)
codes to calculate Vat snd Stamp duty
C# WinForm Desktop App - Connecting Client to Server IP in A