I'm working on a big project and don't have much time to dwell on each problem, I'm using Windows Forms, particularly the DataGridView. I just added a data source that would query a table on the database. The enable add, delete, and edit properties are checked. I created this DataGridView through drag and drop, and adding a datasource. The query works fine when I run the program, the table appears on my DataGridView, I'm able to add, edit and delete rows on the DataGridView, but when I query the table through SQL Server Management Studio, the records in the table remain the same. What could be the problem?
|
The datasource needs to have insert/update/delete commands in order for the gridview to work, and it sounds like it just has a select command. |
|||||||||
|
Unfortunately, you do need to specifically run an update command. Here's a link that may help: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx And here's one that discusses how to auto save to SQL Server, if that's relevant: http://www.codeproject.com/Articles/12846/Auto-Saving-DataGridView-Rows-to-a-SQL-Server-Data This is one reason why I like the Entity Framework/MVC. Very simple data manipulation :D I'd suggest you check it out if you're intersted/have spare time. |
|||
|
if you are using dbnavigator after you done with table you should click on save button on dbnavigator because add and edit and delete do not save in database until you click on save button in dbnavigator. |
|||
|
I've found a solution. I've added a button named "Save Changes". First I make the initial declarations:
This is the Code for loading the DataGridView which populates it:
This is the code for the Save Changes button:
|
|||
|