samedi 14 mars 2015

C# Winforms with MS Access DB, update not working

I can't seem to figure out why my update statement isn't working. I have a lot of similar operations to the database, inserting, selecting, deleting and they are all working well. Except for update, it doesn't seem to work. I've tried the SQL statement in MS Access on the same database, replacing the '@parameters' with values and it worked just fine.


I tried debugging and all the data from my object is valid and correct. But when I execute the command, it returns 0 and no rows were updated. My code is bellow, keep in mind that I'm rather new to C#.



public int UpdateActiviteit(Activiteit activiteit)
{
connection.Open();
OleDbCommand command = new OleDbCommand("Update Activiteit set Naam = @naam, Beschrijving = @beschrijving, TypeActiviteitID = @typeActiviteitId, BonusPunten = @bonusPunten, Datum = @datum where id
= @id", connection);

command.Parameters.Add(new OleDbParameter("@naam", activiteit.Naam));
command.Parameters.Add(new OleDbParameter("@beschrijving", activiteit.Beschrijving));
command.Parameters.Add(new OleDbParameter("@typeActiviteitId", activiteit.TypeActiviteitId));
command.Parameters.Add(new OleDbParameter("@bonusPunten", activiteit.BonusPunten));
command.Parameters.Add(new OleDbParameter("@datum", activiteit.Datum));
command.Parameters.Add(new OleDbParameter("@id", activiteit.ID));

int rowsAffected = command.ExecuteNonQuery();
connection.Close();

return rowsAffected;
}

Aucun commentaire:

Enregistrer un commentaire