Why is my MySqlCommand not actually updating my table?

659 Views Asked by At

I have the following code in Mono, using the MySQL Connector/Net:

try
{
    MatchPersonResult mpr = personServ.MatchPerson(p, "MatchAndStore", null);
    using(MySqlCommand successcmd = new MySqlCommand())
    {
        successcmd.CommandText = "UPDATE myccontacts SET mcid = @mcid, matchresult = @mr, datetimematched = @dtm WHERE id = @id";
        successcmd.Connection = conn;
        successcmd.Parameters.Add("@mcid", MySqlDbType.Int32).Value = int.Parse(mpr.PersonID);
        successcmd.Parameters.Add("@mr", MySqlDbType.Enum).Value = mpr.MatchResultStatus;
        successcmd.Parameters.Add("@dtm", MySqlDbType.DateTime).Value = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
        successcmd.Parameters.Add("@id", MySqlDbType.Int32).Value = person["id"];
        successcmd.ExecuteNonQuery();
        Console.WriteLine(mpr.PersonID);
    }
}

When the query is executed, the table isn't actually updated with anything. I set a breakpoint on the Console.WriteLine call so I can check what's happening and when it's hit, I load the row with the id mentioned in the code and it has not been updated. Even if I don't debug but just let the code execute, I see that nothing is happening to the database. For clarity's sake - personServ.MatchPerson is actually a web reference imported into my solution, so I can check on the other end and do in fact see that the proper data were sent over and that the db update should take place.

Anyone know what to do?

TIA, Benjy

P.S.: Everything except for the db updates is working - the catch block here (not posted for brevity's sake) is never hit.

1

There are 1 best solutions below

0
On

Could u try this code ?

 try
    {
        MatchPersonResult mpr = personServ.MatchPerson(p, "MatchAndStore", null);
        using(MySqlCommand successcmd = new MySqlCommand())
        {
            successcmd.CommandText = "UPDATE myccontacts SET mcid = @mcid, matchresult = @mr, datetimematched = @dtm WHERE id = id";
            successcmd.Connection = conn;
            successcmd.Parameters.AddWithValue("@mcid",int.Parse(mpr.PersonID));
            successcmd.Parameters.AddWithValue("@mr",(int)mpr.MatchResultStatus);
            successcmd.Parameters.AddWithValue("@dtm", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            successcmd.Parameters.AddWithValue("@id",Convert.Int32(person["id"]); 
            successcmd.Connection.Open();
            successcmd.ExecuteNonQuery();
            successcmd.Connection.Close();
            Console.WriteLine(mpr.PersonID);
        }
    }