Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Am using TableMapping to load data to a data grid. as below
daCompanies.TableMappings.Add("tbl_permits", "companies")

I have a refresh button that just calls the same function used to initially load the data on the data grid. The refresh stops at the code above with an error:
The DataTableMapping.SourceTable is required to be unique, 'tbl_permits' already exists in the collection.

How do i clear OR save changes on the DataTableMapping.SourceTable to database and clear it before reloading it with data?

Updated 31-May-11 2:51am
ZeeroC00l 31-May-11 8:52am    
-- added pre, code tag for readability

joseph k 31-May-11 9:27am    
I would like to refresh this at this point:
<pre> DGVCompanies.DataSource = Nothing
DGVCompanies.DataSource = dsCompanies.Tables("companies").DefaultView

1 solution

Read the error message again. You're trying to add two mappings of the same table, when you can only map a table once. Either remove the line that's mapping the table, or check to see if the mapping already exists before you try to add it.
Share this answer
joseph k 1-Jun-11 1:57am    
yes , that is true. I dont want to get rid of the first mapping because it is required when the form loads. My problem is Not the mapping, My problem is , how do i refresh the data grid without compromising the mappings. This is after i do a search and mapping details change and i need the data grid to reflect the new search results

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900