這是我的代碼,我認爲我現在正在做的權利,但我真的不知道是什麼問題。 我正在用txtbox作爲用戶名和密碼的註冊表格,我用MD5加密密碼,我試圖刪除MD5加密思想,認爲它可能是prtoblem,但仍然當我刪除它時,問題仍然存在。我試圖用C#txtbox形式在mysql數據庫中插入數據,但是我總是得到一個錯誤?
ApareceCrudLib a = new ApareceCrudLib("localhost", "root", "", "cashieringdb");
string query = "INSERT INTO register (username,password) " +
"VALUES(" +
"'" + txtUser.Text + "'," +
"MD5('" + txtPass.Text +"')";
a.mysqlInsert(query);
MessageBox.Show("Account has been registered!");
this.Close();
這是mysqlInsert
public void mysqlInsert(string query)
{
try
{
if (this.Open())
{
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.ExecuteNonQuery();
this.Close();
System.Windows.Forms.MessageBox.Show("Record Inserted!");
}
}
catch { this.Close(); System.Windows.Forms.MessageBox.Show("INSERT Record Error!"); }
return;
}
,你可以看到我趕上與對話框中的錯誤所以基本上,如果它將無法插入或連接到數據庫的消息框我的課ApareceCrudLib代碼顯示「INSERT Record Error!」。順便說一句,只有在插入到數據庫時,Visual Studio沒有錯誤。
我認爲錯誤的地方在代碼中插入數據庫的查詢字符串=「INSERT
INTO register (username,password) " +
"VALUES(" +
"'" + txtUser.Text + "'," +
"MD5('" + txtPass.Text +"')";
也許逗號分號一段時間我無言以對。
嗨!rhughes這裏是錯誤的圖像!
什麼是錯誤 –
,你可以看到我趕上與對話框中的錯誤?所以基本上如果它將無法插入或連接到數據庫的消息框顯示「插入記錄錯誤!」順便說一句,沒有錯誤在Visual Studio中只插入到數據庫中 – JustNoobWillingToLearn
答案是正確的,並且異常消息會告訴你:知道有錯誤是不夠的;你需要知道錯誤實際上是什麼 –