Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void loginControl_Authenticate(object sender, AuthenticateEventArgs e)
    {
        Employee user = new Employee();
        user.EmployeeID = Convert.ToInt32(loginControl.UserName);
        user.Password = loginControl.Password;
        e.Authenticated = EmployeeDAO.authenticateEmployee(user);



        if (e.Authenticated)
        {
            Response.Redirect("DefaultSecure.aspx");
        }
    }

this is my code of inpun on user name and paswd but it showing Input string was not in a correct format this error.i ma not geting plz help
Posted
Comments
ridoy 26-Dec-12 11:52am    
what is loginControl? where you initialize it?
Anele Ngqandu 27-Dec-12 5:06am    
what is the format of the EmployeeID?

Look at your code: there is only one place that can generate that error.
C#
user.EmployeeID = Convert.ToInt32(loginControl.UserName);

From that, the clue is in the Property name: loginControl.UserName is unlikely to be a number, so the Convert.ToInt32 will throw an error.

I suspect you want a different property.
 
Share this answer
 
Comments
Eknath Sonawane 26-Dec-12 12:03pm    
so which property will be suit over here
OriginalGriff 26-Dec-12 14:10pm    
Well that's up to you - you know what control you are using, not me! I'd suggest an integer one or perhaps a lookup from the name to the ID?
Bear in mind I can only see the seven lines of code you posted above...
This might helps you. Use
C#
user.UserName  = loginControl.UserName;

instead of
C#
user.EmployeeID = Convert.ToInt32(loginControl.UserName);
 
Share this answer
 
Comments
Eknath Sonawane 26-Dec-12 23:22pm    
this is my function still this is not working
public static bool authenticateEmployee(Employee employee)
{
string query = "SELECT EmployeeID FROM Employee WHERE EmployeeID = @EmployeeID AND Password = @Password";
SqlCommand command = new SqlCommand(query);
command.Parameters.AddWithValue("@EmployeeID", employee.EmployeeID);
command.Parameters.AddWithValue("@Password", employee.Password);
DataTable dataTable = executeQuery(command);

if (dataTable.Rows.Count > 0)
return true;

return false;
}
[no name] 26-Dec-12 23:27pm    
Do you have any username (Login ID) field in your database? Use it instead of EmployeeID. I am expecting EmployeeID to be the primary key of your table.
C#
user.EmployeeID = Convert.ToInt32(loginControl.UserName);


brother make sure that Employee has the prpoerty EmployeeID type of string?

C#
command.Parameters.AddWithValue("@EmployeeID", employee.EmployeeID);


explain here first that what is data type of EmployeeID in your database?
also, what is the data type of EmployeeID in your object? then some one would guess, what's going on exactly
 
Share this answer
 
Comments
Eknath Sonawane 27-Dec-12 1:57am    
Emplpyee having property EmployeeId of type Int
Eknath Sonawane 27-Dec-12 1:58am    
i am aslo chengit it to string but it didt rpl if u dnt mind will u please sned me ur emailid i will send u the project plz help
Faisalabadians 27-Dec-12 2:06am    
craze.programmer@gmail.com
Faisalabadians 27-Dec-12 2:07am    
also, database or database script would be required.
Eknath Sonawane 27-Dec-12 5:13am    
just check out your mail i have just send u that project

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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