Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in my program employee ID is displyed like emp0000001,emp0000002.but in database it is stored like 1,2,3...
in my login authentication page uses employee Id text box.here i need to type employee ID like emp0000001.but in data base the employee iD is '1'.i want to remove emp000000 from the text box.
then how can i rectify my login problm.
Posted
Comments
Sergey Alexandrovich Kryukov 6-May-13 2:24am    
Why storing such gibberish as "emp0000001" in a text box? Why text box at all? It should be a text box is the user types in it.
—SA
geo thomas 6-May-13 2:36am    
its not storing in the data base as emp0000001...it stores as 1..
Sergey Alexandrovich Kryukov 6-May-13 2:42am    
You are not answering my question...
—SA
geo thomas 6-May-13 2:54am    
string rem = txt_EId.Text;
string sa;
sa= rem.Replace("emp","");
int a = Convert.ToInt32(sa);
//MessageBox.Show(a.ToString());
SqlConnection s = new SqlConnection();
s.ConnectionString = @"Data Source=.;Initial Catalog=employee;User ID=sa;Password=tecfwds@hg25tr32";
s.Open();
string st = "select Employee_Id,Password from Employee_Details where Employee_Id='" +a.ToString() + "' and Password='" +txt_pwd.Text+ "'";
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
da.SelectCommand = new SqlCommand(st, s);
da.Fill(dt);
if (dt.Rows.Count > 0 && rem.Contains("emp"))
{
MessageBox.Show("login successfull");
}
else
{
MessageBox.Show("invalid user id and pass word");
}

this code works
Sergey Alexandrovich Kryukov 6-May-13 3:00am    
You are not answering my question...
—SA

1 solution

You should re-desing the UI and re-think you approaches. If you force the users to type such gibberish, you abuse people patience. And the problem is artificial. Who told you that you should create a query directly based on UI data? This is simply unsafe. Do you want to understand why? Look here:
http://xkcd.com/327/[^].

See also:
EROR IN UPATE in com.ExecuteNonQuery();[^].

—SA
 
Share this answer
 
Comments
geo thomas 6-May-13 23:53pm    
kk..thank u
Sergey Alexandrovich Kryukov 7-May-13 1:26am    
You are welcome. I suggest you accept this answer and re-think you approach accordingly. You follow-up questions will be welcome.
—SA

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