As the title says I'm trying to change the rating of a book in my database via my GUI. I change it from 1 to 5 for example. When I use breakpoints I see that the query translates correctly to what it should be (I think) and I get no errors. Yet it doesn't change the actual row in the database.
public int ChangeRating(Book book, int rating, string title)
{
book.Query = "UPDATE Books SET Rating = " + rating + " WHERE Title = '" + title + "'";
return SqlManager.RunNonQuery(book);
}
After that it goes to my SqlManager.
public static int RunNonQuery<T>(T value) where T : IIsQueriable, new()
{
using (SqlConnection con = new SqlConnection(cs)) //connectie wordt aangemaakt
{
using (SqlCommand cmd = con.CreateCommand()) //maakt een command aan
{
cmd.CommandText = value.Query; //de waarde van Query wordt de command
return TryExecuteNonQuery<T>(cmd);
}
}
}
private static int TryExecuteNonQuery<T>(SqlCommand cmd) where T : IIsQueriable, new()
{
int result;
try
{
cmd.Connection.Open();
cmd.Prepare();
result = cmd.ExecuteNonQuery();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
finally
{
cmd.Connection.Close();
}
MessageBox.Show(result.ToString());
return result;
}
in the database. Rating is an int and the title is a Nvarchar(MAX) incase that matters.