![]() |
|
[C#] C# Updating SQL Table - Table not updating - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] C# Updating SQL Table - Table not updating (/showthread.php?tid=5417629) |
C# Updating SQL Table - Table not updating - siimon00 - Sep 27, 2016 Hello Guys! I'm trying to update my SQL table in C#. I've been struggling with updating the table for a couple hours now, and I've searched so much, I can't wrap my head around what is wrong. Code public class SQLConnectThe focus is on the IndtastBeløb method, im trying to determine if there is an entry in the database for the current date, if there is I want to update that row. Everything in the code works until I'm trying to update with the changeRow.ExecuteNonQuery(); The program doesn't throw an exception or give me any errors, the database simply does not change :) I hope that someone out there can help me! :) * - Yoshi - Sep 27, 2016 Have you tried setting breakpoints and check if the variables got the right values? * - siimon00 - Sep 27, 2016 Hi Yoshi. Yes I have actually! and all of the variables got the exact values from the database as they should. if I run it with: int affectedRows = changeRow.ExecuteNonQuery(); affectedRows even = 1 after the query. But when I check my database nothing has changed * - Temploit - Sep 27, 2016 Most libraries require you to do some sort of Commit after an insert query. Look at the example of this page: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit(v=vs.110).aspx * - Ninja - Sep 27, 2016 Code connectionSuccesful = false;Also, you should really handle that try catch statement better in the OpenConnection function. Make it so it tells you what is wrong with the connection so end users could maybe even know how to fix it, or make it retry, or something. Dont just set a bool to false. * - some_dude13 - Sep 28, 2016 Are you a 100% sure the update clause used in your tests is valid and would affect an existing row? Are there records in your table with a day equivalent to "today" on the day you run your test? Another note, the code inside your read statement seems to reset almost all variables each iteration, I don't know what you are specifically trying to accomplish, but on first impressions it seems like you want to use iBolig,iOther,iTransport,iLoan,iMad and iDiverse as accumulators, yet their value is changed each iteration, maybe I am wrong depending on your needs. |