Copy DataRows to Typed DataSet

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
 
A

Andy Becker

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top