Datagridview database not updating

16-Jun-2015 20:49 by 2 Comments

Datagridview database not updating

So, I begain experimenting by placing my update code into various events.I tried in conjunction with my update sub, but none of those would update the database when the focus left the edited row. Surley it's possible to commit the changes made on the Data Grid View to the database when the focus is moved off the edited/new row.

datagridview database not updating-55

Microsoft is conducting an online survey to understand your opinion of the Msdn Web site.If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site. Open(); using (Ole Db Command cmd Update = new Ole Db Command(_command Update, conn)) using (Ole Db Command _cmd Select = new Ole Db Command(_command Select, conn)) using (Ole Db Command _cmd Update = new Ole Db Command(command Update, conn)) { _cmd Select. Default View[row Num]["Product Code"]); int quantity = Convert. Default View[row Num]["Quantity"]); int price = Convert. Default View[row Num]["Sub Total"]); int _price = Convert. Default View[row Num]["Total"]); using (Ole Db Connection conn = new Ole Db Connection(connection String)) { string _command Select = "SELECT [Quantity], [Sub Total], [Total] FROM [Trans Record] WHERE [Product Code] = @Product Code"; string command Update = "UPDATE [Record] SET [Quantity] = @Quantity, [Sub Total] = @Sub Total, [Total] = @Total WHERE [Product Code] = @Product Code"; string _command Update = "UPDATE [Trans Record] SET [Quantity] = @Quantity, [Sub Total] = @Sub Total, [Total] = @Total WHERE [Product Code] = @Product Code"; conn. I have a Data Grid View that is attached to a Binding Source that gets data from a SQL Server database.I can populate the Data Grid View without a problem.

I can even insert/update it without issue if I run the update code from a click event of a button.But where I run into issues is when I try to update the database as soon as the user is done editing a row.I thought that the event would be perfect for that, but it actually does not commit the changes until it has been fired twice (that is, after an edit, I have to click on a different row or arrow down twice before the edit shows up in the database).Then I thought why not call the update code on both the ?That worked fine for updates, but then I found that three records were inserted into the database when I added a new row to the Data Grid View (the data gets inserted, then a null value, then the data again).After digging around on the web for most of the day, I found that the , but would when using a click on a save button (since all the Data Grid View events would complete before the button click event fires).