SUPER KUNG FU
27-03-2009, 01:00
public void TestDangNhap()
{
string sql = "";
sql = "select * from DangNhap where UserName = '" + textBox1.Text + "' ";
sql += "AND Passwords = '" + textBox2.Text + "' ";
SqlConnection myConn = new SqlConnection();
string str_connect = @"Data Source= supercomputer;" +
"database=QuanLyMuaBan;" +
"User ID =;" +
"Password =;" +
"Integrated Security=SSPI;" +
"Persist Security info =false";
myConn.ConnectionString = str_connect;
myConn.Open();
string sqlquery = "select * from DangNhap";
SqlDataAdapter myadapter = new SqlDataAdapter(sqlquery, myConn);
DataTable myTable = new DataTable();
myadapter.Fill(myTable);
bool flag = false;
for (int i= 0;i < myTable.Rows.Count; i++)
{
string a = myTable.Rows["UserName"].ToString();
string t = myTable.Rows["Passwords"].ToString();
if (textBox1.Text.Equals(a.Trim()) && (textBox2.Text.Equals(t.Trim())))
{
flag = true;
break;
}
}
if (flag == true)
{
Main f = new Main();
f.Show();
this.Hide();
}
else
{
MessageBox.Show("Sai pass ho?c m?t kh?u");
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
myConn.Close();
}
{
string sql = "";
sql = "select * from DangNhap where UserName = '" + textBox1.Text + "' ";
sql += "AND Passwords = '" + textBox2.Text + "' ";
SqlConnection myConn = new SqlConnection();
string str_connect = @"Data Source= supercomputer;" +
"database=QuanLyMuaBan;" +
"User ID =;" +
"Password =;" +
"Integrated Security=SSPI;" +
"Persist Security info =false";
myConn.ConnectionString = str_connect;
myConn.Open();
string sqlquery = "select * from DangNhap";
SqlDataAdapter myadapter = new SqlDataAdapter(sqlquery, myConn);
DataTable myTable = new DataTable();
myadapter.Fill(myTable);
bool flag = false;
for (int i= 0;i < myTable.Rows.Count; i++)
{
string a = myTable.Rows["UserName"].ToString();
string t = myTable.Rows["Passwords"].ToString();
if (textBox1.Text.Equals(a.Trim()) && (textBox2.Text.Equals(t.Trim())))
{
flag = true;
break;
}
}
if (flag == true)
{
Main f = new Main();
f.Show();
this.Hide();
}
else
{
MessageBox.Show("Sai pass ho?c m?t kh?u");
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
myConn.Close();
}