hi friends
i have two forms
1.login form
2.timesheet form
log inform database has employeeid,username,password.
statically i give someusername,password in database table.
now username,password is correct it will redirect to timesheet form
my query is
how can i get the employee id using username in timesheetform
i want to store employee id in session
thanks in advance
regards
saravanan
PHANI NADIGADDAPosted Feb 2, 2007, 11:17 AM
There is another you can do this. It helps you not to get much data from the database and it is light weight. You are performing both at a time. It returns employeeid if username and password both are correct other wise it retuns 0 records.
stored procedure
----------------
create procedure spAuthenticateUser
(
@username varchar(10),
@password varchar(10)
)
AS
BEGIN
SELECT employeeid WHERE UserName = @username AND Password = @password;
END
GO
This stored procedure returns employeeid if username and password are correct.
.cs
---
public int AuthenticateUser(string userName, string password)
{
SqlConnection connection = new SqlConnection("ConnectionString");
connection.Open();
SqlCommand command = new SqlCommand("spAuthenticateUser", connection);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
int employeeId =0;
if(reader.Read())
{
employeeId = Convert.ToInt32(reader["employeeid"]);
}
return employeeId;
}
}
-------------
It returns employeeid if username and password are correct other wise returns 0.
submitclick()
--------
int employeeId = AuthenticateUser("username", "password");
if(employeeId == 0)
Authentication Failed. Invalid username and password.
else
Session["employeeid"] = employeeid;
ALL THE BEST
sivaPosted Feb 1, 2007, 2:40 AM
Hi,
In the login page keep the login user employee id in session
For example
Session ["employeeid "] = DSUserInfo.Tables[0].Rows[0][" employeeid "];
Now in the timesheetform you can call the session like this
Int employeeid;
employeeid = Convert.ToInt32(Session ["employeeid "]);