Help with data update
-
Hello, could anyone solve my problem. I have application working with MSSQL Server: there is one table "goods" (id, name) and another one - "info" (id, idgood1, idgood2, info), where idgood1 and idggod2 - foreign keys. In my application I need to present a DataGridView in such a way, _______| goods1 | goods2 | goods3 goods1 | info11 | ______ | ______ goods2 | ______ | ______ | info23 goods3 | info31 | ______ | info33 I select data from two tables ("goods", "info") in appropriate DataTable instances: GoodsDataTable and InfoDataTable. Then I CREATE (dynamically) one more DataTable - VisualDataTable, which IS what i need. Then I put VisualDataTable into DataSet, DataSet into BindingSource, and, finally, BindingSource into DataGridView. It's working. Until I want to update something! I tried to call SqlAdapter's Update method as for InfoDataTable as DataSet. But nothing happens. In general, how should I update data in case when "visual" part of DataGridView and database structure are different..? Another words, I take data from database, and put data into database with one table, and I edit data with another table.
-
Hello, could anyone solve my problem. I have application working with MSSQL Server: there is one table "goods" (id, name) and another one - "info" (id, idgood1, idgood2, info), where idgood1 and idggod2 - foreign keys. In my application I need to present a DataGridView in such a way, _______| goods1 | goods2 | goods3 goods1 | info11 | ______ | ______ goods2 | ______ | ______ | info23 goods3 | info31 | ______ | info33 I select data from two tables ("goods", "info") in appropriate DataTable instances: GoodsDataTable and InfoDataTable. Then I CREATE (dynamically) one more DataTable - VisualDataTable, which IS what i need. Then I put VisualDataTable into DataSet, DataSet into BindingSource, and, finally, BindingSource into DataGridView. It's working. Until I want to update something! I tried to call SqlAdapter's Update method as for InfoDataTable as DataSet. But nothing happens. In general, how should I update data in case when "visual" part of DataGridView and database structure are different..? Another words, I take data from database, and put data into database with one table, and I edit data with another table.
Your design is a bit blur. What I understand form your post is that you combine two tables into one, this is called DataView object which should be in the SQL server layer of your program. Create a SqlCommand that creates a DataView combining both tables then make your SELECT/UPDATE commands on that view. Both tables will be updated accordingly. I hope I got you right.
Regards:rose:
-
Your design is a bit blur. What I understand form your post is that you combine two tables into one, this is called DataView object which should be in the SQL server layer of your program. Create a SqlCommand that creates a DataView combining both tables then make your SELECT/UPDATE commands on that view. Both tables will be updated accordingly. I hope I got you right.
Regards:rose:
OK, I'll show an example "Goods" Table:
id | name --------- 23 | foo1 24 | foo2 25 | foo3
"Info" Table:
id | idgood1 | idgood2 | info ----------------------------- 10 | _____23 | _____24 | inf1 11 | _____23 | _____25 | inf2 12 | _____24 | _____25 | inf3
I want to see in DataGridView such structure (first row - row header, first column - column header):
____ | foo1 | foo2 | foo3 -------------------------- foo1 | ____ | inf1 | inf2 foo2 | ____ | ____ | inf3 foo3 | ____ | ____ | ____