Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2010 Deleting a copied datatable from the original

$
0
0
Hi,

I have a table of (lets just say) 'customers' that I create a subset using the following statement:

Code:

CustomersTable.Select("CustomerID=2").CopyToDataTable(SingleCustTable, LoadOption.PreserveChanges)
The newly created 'SingleCustTable' I then pass to another form for the user to configure some options. The problem I have is when this form returns the 'SingleCustTable'.

Essentially what I'm trying to do is keep track of customer records in the master 'CustomersTable' for each customerID.

The code I use when the configuration changes are made is:

Code:

Dim RetVal as Byte = f.ShowDialog  ' f is the form that uses the individually created 'SingleCustTable'
If RetVal = vbOK Then
' If the customer has changed the data in their 'SingleCustTable' (i.e. the local copy I pass to the form)
CustomersTable.Merge(f.MyTable) ' MyTable is a property in the form that gives me access to the instance of the SingleCustTable I passed to it
End If

The issue I'm having is that everytime the form is opened and the user clicks OK the same rows are added to the 'CustomersTable' so I get duplicates. I hoped the merge method might be able to handle this but it looks like I might have to delete the rows that are captured in the 'SingleCustTable' when the user clicks OK.

Does anybody know if there is a simple way to handle a subset of table which can then easily be merged back into the table the subset was created from?

As an aside I've tried to delete the rows and that failed!

I used:

Code:

For Each CustRow in SingleCustTable
CustomersTable.RemoveRow(CustRow)
Next CustRow

The above raises an exception though - indicates that the row doesn't exist in the CustomersTable.

Any help would be appreciated.
Thanks,
N

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>