简体   繁体   中英

DataGridView + Datatable Queried From Mutiple Tables

I can create a DataGridView bound to a datatable, which queries a single table, or even multiple tables via a dataset (xsd).

I want to use a query to return data from a foreign table, where a related price is held. I need to display this [readonly] price, so the user can make the right changes to the 'main' data, based on the price it references.

However, I cannot get updates to work, as the XSD will not create an update routine for the datatable as a whole, as it queries data outside of the table.

I can manually create update commands, but they only except single parameters on a per row basis, rather than taking a datatable, to update changes. Is it possible to achieve what I want?

Sub Load
adapter.fill(QueriedDataTable)
dgvMain.datasource = QueriedDataTable
End Sub

Sub Update
adapter.update(QueriedDataTable)
End Sub

If I understand you correctly, then what you need to do is include both tables in your dataset as separate tables, rather than combining them using a join query. The table adapter for the main table will then include an Update query. You should then add an expression column to the main table, pulling the price from the parent prices table. You can then bind the datagridview to the main table only. Incidentally, to populate the Prices table, you don't necessarily need to pull the entire table. You can use a JOIN query to the main table, but only list fields from the Prices table in the SELECT clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM