我的登錄表單正在運行,但是當我在單詞的第一個字母中輸入大寫字母的用戶名並且數據庫中的用戶名全部爲小寫字母時,仍然允許訪問和登錄成功的。登錄表單中的大小寫敏感C#
你能幫我解決這個問題嗎? 我真的需要你的幫助。
這是我當前的代碼
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("Input Required Fields!",
"Note",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
else
{
//Passing the value from textbox
Tic_Tac_Toe frm2 = new Tic_Tac_Toe(textBox1.Text);
View view = new View(textBox1.Text);
string str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Majel\Tic Tac Toe\Database\Database.mdb";
OleDbConnection con = new OleDbConnection(str);
OleDbCommand cmd = new OleDbCommand("SELECT COUNT(*) FROM data WHERE Users = '" + textBox1.Text + "' AND Pass = '" + textBox2.Text + "'", con);
con.Open(); try
{
int i;
i = Convert.ToInt32(cmd.ExecuteScalar());
if (i == 1)
{
MessageBox.Show("Login Successful!",
this.Hide();
frm2.Show();
}
else
{
MessageBox.Show("Invalid User Name or Password",
"Note",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
}
有人能幫助我嗎?提前謝謝你。
添加'WHERE'條款到SQL制約了登錄用戶的變更到你。 – DeanOC 2014-09-25 23:50:30