我正在做一個登錄和註冊表格,當我嘗試註冊它把用戶名和密碼在SQL數據庫中,但它這樣做:
我的項目看起來是這樣的:Parameters.Add在SQL項目C#
static public void Insert(string _userName)
{
try
{
connection.Open();
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table](username) VALUES(@userName)", connection);
commandInsert.Parameters.Add("@userName", _userName);
commandInsert.ExecuteNonQuery();
}
catch (SqlCeException expection)
{
MessageBox.Show(expection.ToString());
}
finally
{
connection.Close();
}
}
static public void Insertt(string _password)
{
try
{
connection.Open();
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table](password) VALUES(@Password)", connection); ;
commandInsert.Parameters.Add("@password", _password);
commandInsert.ExecuteNonQuery();
}
catch (SqlCeException expection)
{
MessageBox.Show(expection.ToString());
}
finally
{
connection.Close();
}
}
和按鈕註冊看起來像這樣:
private void button1_Click(object sender, EventArgs e)
{
if (insertBox.Text != "" || deleteBox.Text != "")
{
SQLFunctions.Insert(insertBox.Text);
SQLFunctions.Insertt(deleteBox.Text);
SQLFunctions.Refresh(this.dataGridView1);
}
else
{
MessageBox.Show("login failed");
}
}
感謝您的幫助
請說明問題,不只是把我們的程序,並且希望我們的調試/修復它爲您 – Steve 2014-10-09 17:20:46
你爲什麼將在單獨的記錄的用戶名和密碼?爲什麼有兩個功能呢?是什麼讓'Insertt'與'Insert'不同?另外,請不要以純文本存儲用戶密碼。如果用戶使用他們的密碼信任您,請妥善散列這些密碼,以免他們被讀取。 – David 2014-10-09 17:24:13