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
omidPosted Jul 20, 2009, 1:52 PM
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] .
shimaPosted Jul 21, 2009, 2:08 AM
it's very good
Best Regard
shimaPosted Jul 19, 2009, 6:02 AM
I think this question is very simple!!!
shimaPosted Jul 19, 2009, 2:54 AM
IF username and password is correct then show menu page
ELSE show message box
thanks
Scott KnakePosted Jul 18, 2009, 9:44 AM