hi
I have problem with login form in c#
I think this problem from if statment
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=pjt;Integrated Security=True");
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "SELECT * FROM LOGIN WHERE username='" + tusername.Text +"' AND password=" + tpassword.Text +"'";
SqlDataReader dr =com.ExecuteReader();
if(Convert.ToBoolean(com.CommandText))
{
Menu oform = new Menu();
oform.Show();
}
else
{
MessageBox.Show("username or password incorrect");
}
con.Close();
Loading

omid9 reputationPosted Jul 20, 2009, 9:52 AM EDT
if before this section everything is fine, it should work. Because you've checked pass in sql command. and your reader should have a record after read command, if the pass is correct. read function return true if there's a record in dr. also you can access the record by using dr as an array. like this: (string)dr[0] .
Scott Knake30 reputationPosted Jul 18, 2009, 5:44 AM EDT
shima32 reputationPosted Jul 18, 2009, 10:54 PM EDT
IF username and password is correct then show menu page
ELSE show message box
thanks
shima32 reputationPosted Jul 19, 2009, 2:02 AM EDT
I think this question is very simple!!!
shima32 reputationPosted Jul 20, 2009, 10:08 PM EDT
it's very good
Best Regard