這個問題有點難以解釋,但是在這裏。我有一個從本地SQLiteDatabase在線添加記錄到MySQL數據庫的函數。首先調用一個函數來檢索本地數據,並將每行發送到上載函數,該函數將記錄添加到在線MySQL數據庫中。當從另一個函數A調用這些函數時,它可以很好地工作,但是從不同的函數調用時。函數B重複記錄被輸入到數據庫中。重複自身導致數據庫中重複記錄的代碼
在調試過程中嘗試解決問題時,我發現當它複製記錄時,它將轉到cmd.executeNonQuery(),然後轉到下一行,但無緣無故將返回到cmd.executeNonQuery ()因此重複記錄。代碼如下
private void uploadDatabase(string company, string oldCompany, string companyURL, string loginUsername, string oldUsername, string password, string type, string perform, string direction)
{
Boolean recordFound = false;
recordFound = checkRecordNotExist(company, loginUsername);
MySQLDBWork dbase = new MySQLDBWork();
try
{
dbase.openConnection();
if (perform == "insert" && !recordFound)
{
string query = "INSERT INTO `" + username + "` (pas_company, pas_companyURL, pas_username, pas_password, pas_type) "
+ "VALUES ('" + company + "', '" + companyURL + "', '" + loginUsername + "', '" + password + "', '" + type + "')";
Console.WriteLine("Query: " + query);
MySqlCommand cmd = new MySqlCommand(query, dbase.conn);
cmd.ExecuteNonQuery();
recordFound = true;
query = "";
company = "";
loginUsername = "";
cmd.Dispose();
}
if (perform == "delete")
{
string query = "DELETE FROM `" + username + "` WHERE pas_company='" + company + "' AND pas_username='" + loginUsername + "'";
dbase.performQuery(query);
}
}
catch (MySqlException ex)
{
Console.WriteLine("Adding Online Error: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("General Exception: " + ex.Message);
}
finally
{
dbase.closeConnection();
//dbase.conn.Dispose();
company = null;
loginUsername = null;
}
}
的問題是,如果語句中執行==「插入」 & &!recordFound。
我不確定上面的代碼是否有助於解決問題,但這是從函數b調用時出錯的函數,但在函數A中正常工作。感謝您提供的任何幫助和建議。
你確定你是(1)使用最新的源代碼(也許,重建會有幫助),和(2)調試調試,而不是你的應用程序的發佈版本? – Vlad 2011-01-30 19:50:21