Code repeating itself causing duplicate records in database
<p>this problem is a bit of a difficult one to explain but here it goes. I have a function which adds a record to a MySQL Database online from a local SQLiteDatabase. A function is first called to retrieve the local data and each line is sent to the upload function which adds the record to the online MySQL Database. When these functions are called from a another function A it works fine but when called from a different function. Function B duplicate records are entered into the database. </p>

<p>During debugging to try and resolve the problem I find that when it is duplicating records it is going to cmd.executeNonQuery() then going to the next couple of line but then for no reason will go back up to cmd.executeNonQuery() therefore duplicating the record. The code is below</p>

<pre><code> 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" &amp;&amp; !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;
            }
        }
</code></pre>

<p>The problem is within the if statement perform == "insert" &amp;&amp; !recordFound. </p>

<p>I'm not sure if the code above will help to solve the problem but this is the function that is going wrong when called from function b but works fine from function A. Thanks for any help and suggestions you can offer. </p>
