-1
我使用短小精悍庫的東西是錯在這裏我似乎無法使其工作,即使密碼或用戶名錯了,它開闢了新的形式,使一個登錄表單C#小巧玲瓏如何知道查詢是正確的
if (string.IsNullOrEmpty(txtUsername.Text))
{
MessageBox.Show("Please enter your usernmae.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUsername.Focus();
return;
}
try
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
var data = db.Query("select Username,Password from UserLog", commandType: CommandType.Text);
if ((data.SingleOrDefault() !=null)
{
MessageBox.Show("You have been succesfully logged in.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
FormHome frm= new FormHome();
frm.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("Your Username or Password is Incorrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
看看數據內容,爲什麼' data.SingleOrDefault()!= null'始終爲真。 – Vladimir