string connetionString = null;
SqlConnection sqlCnn;
SqlCommand sqlCmd;
SqlDataAdapter adapter = new SqlDataAdapter();
DataTable ds = new DataTable();
int i = 0;
string sql = null;
connetionString = " Data Source=BAOPC;Initial Catalog=username-password;Integrated Security=True";
sql = "Select * from passwordandusername";
sqlCnn = new SqlConnection(connetionString);
try
{
sqlCnn.Open();
sqlCmd = new SqlCommand(sql, sqlCnn);
adapter.SelectCommand = sqlCmd;
adapter.Fill(ds);
for (i = 0; i <= ds.Rows.Count - 1; i++)
{
int result = string.Compare(txtpassword.Text,ds.Rows[i].ItemArray[2].ToString() );
if(result==0)
MessageBox.Show("0k");
}
adapter.Dispose();
sqlCmd.Dispose();
sqlCnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
code của mình đây nhá. Bạn xem hộ mình với.