Copy DataRows to Typed DataSet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I developed a custom Windows control that displays a data grid of all orders
for a customer.

Since the control only needs to use the Orders table within the parent data
set (along with the customer ID to filter), it seemed logical to only give
the control what it needs. That's my reasoning for the code below...

\\\
Public Sub New(ByRef Orders As myTypedDataSet.OrdersTable, _
ByVal CustomerID As Integer)

MyBase.New()
InitializeComponent()

dsLocal.Orders = Orders
_Customer_ID = CustomerID

End Sub

Private _CustomerID As Integer
Private dsLocal As myTypedDataSet

Private Sub ctlOrdersForCustomer_Load(ByVal _
sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load

myDataView.Table = dsLocal.Orders
myDataView.RowFilter = "CustomerID = " & _CustomerID.ToString
myDataView.Sort = "OrderDate DESC"

myGrid.DataSource = myDataView

End Sub
///

My problem is that I can't pass the Orders table as an argument because it
is part of a typed data set. VS.NET complains about dsLocal.Orders being
read-only in the following statement of the constructor:

dsLocal.Orders = Orders

How can I set the local typed dataset table to the incoming parameter? I've
also tried the Copy, ImportRow, and LoadDataRow methods with no luck. Does
anyone know how this can be done?

Thank you very much!

Eric
 
How can I set the local typed dataset table to the incoming parameter? I've
also tried the Copy, ImportRow, and LoadDataRow methods with no luck. Does
anyone know how this can be done?

Thank you very much!

Eric

One way would be to pass OrdersTable.DefaultView as a DataView for the
parameter, instead of the typed dataset itself. Then your existing Load
code (except for the Table = part) could simply work against that view
instead of creating one.

Best Regards,

Andy
 
Thank you, Andy.

Andy Becker said:
One way would be to pass OrdersTable.DefaultView as a DataView for the
parameter, instead of the typed dataset itself. Then your existing Load
code (except for the Table = part) could simply work against that view
instead of creating one.

Best Regards,

Andy
 
Back
Top