Re: Create 1DataTable from a Select from DataTable
From: Doug Bell (dug_at_bigpond)
Date: 12/06/04
- Next message: Gary Kahrau: "Re: Module Syntax help"
- Previous message: Doug Bell: "Re: Create 1DataTable from a Select from DataTable"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Create 1DataTable from a Select from DataTable"
- Next in thread: Doug Bell: "Re: Create 1DataTable from a Select from DataTable"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 7 Dec 2004 08:11:01 +1100
Hi Jay,
Thanks.
The problem does not seem to be the copy and clear as the original table
still has a row count of 428 and the array holding the rows has a count of
0. But the using clone looks much better. I thought that Clone would be like
creating a DAO Recordset clone (not what I wanted).
I will also use the For each loop.
The problem really seems to be in the Selection but if the syntax and
structure is right then I can't see why, I have found problems with the
Field Names being case sensitive and the DB returning them capitalised even
if they are aliased ( Select PORD AS PONo From... returns PONO).
I will make changes you advised and try some more.
Thanks
Doug
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:%23%23VEpQ72EHA.3128@TK2MSFTNGP14.phx.gbl...
> Doug,
> > My problem is that OrderRows has a Row Count of 0 and yet I can see
valid
> > records there.
>
> > dtOrderDetails = dsPOs.Tables("PODetails")
> > dtOrderDetails.Clear()
> You just cleared dsPOs.Tables("PODetails")!
>
> DataTable is a reference type, when you assign one reference
> variable/property to another you are making a copy of the reference. Both
> variables (dtOrderDetails & dsPOs.Tables("PODetails")) refer to the exact
> same DataTable object on the heap. If you call Clear on the one variable
you
> are also calling clear on the other variable.
>
> Instead of the above two lines, you can use the following single line:
>
> > dtOrderDetails = dsPOs.Tables("PODetails").Clone()
>
> This creates an empty copy of the structure of your DataTable. If you used
> .Copy() (as Cor mentioned in your earlier post) you would get the
structure
> & data of your DataTable.
>
> The rest of your code should work. I normally use a For Each instead of a
> For, mostly to avoid "off by one" problems, however that should not cause
a
> problem with your code.
>
> For Each row As DataRow in OrdersRows
> dtOrderDetails.ImportRow(row)
> Next i
>
> Hope this helps
> Jay
>
> "Doug Bell" <dug@bigpond> wrote in message
> news:%23EbJtD62EHA.3128@TK2MSFTNGP14.phx.gbl...
> > Hi,
> > I am having problems trying to create a (temporary) DataTable from a
> > selection from a DataGrid (dgOrders).
> >
> > dtOrdDetails is declared as a Public DataTable
> >
> > Sub is:
> >
> > Dim stFilter as String
> > Dim OrdersRows() as DataRow
> > 'If OrderNo = "" then Order is an ASN
> > If gstOrderNo = "" Then
> > 'ASN Selection
> >
> > Else
> > 'OrderNo Selection
> >
> > 'Create structure for dtOrderDetails
> > dtOrderDetails = dsPOs.Tables("PODetails")
> > dtOrderDetails.Clear()
> >
> > 'Set Filter - Column [PONo] = Selected Order No.
> > stFilter = "PONo = " & gstOrderNo
> > OrdersRows = dsPOs.Tables("PODetails").Select(stFilter)
> >
> > 'Populate dtOrderDetails
> > For i = 0 to OrdersRows.GetUpperBound(0)
> > dtOrderDetails.ImportRow(OrderRows(i))
> > Next i
> >
> > End If
> >
> > My problem is that OrderRows has a Row Count of 0 and yet I can see
valid
> > records there.
> > I have also tried:
> > stFilter = "PONo = '" & gstOrderNo & "'"
> > stFilter = "PONO = " & gstOrderNo
> > stFilter = "PONO = " & gstOrderNo & "'"
> > Actual Alias Field Name is PONo but I have noticed the DB2 Database
> > returns
> > Columns capitalised.
> > Field Type is Decimal 8,0
> >
> > I can step through the DataTable "PODetails" and can see PONo = the
> > Selected
> > Filter Number.
> >
> > Thanks for any help,
> >
> > Doug
> >
> >
>
>
- Next message: Gary Kahrau: "Re: Module Syntax help"
- Previous message: Doug Bell: "Re: Create 1DataTable from a Select from DataTable"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Create 1DataTable from a Select from DataTable"
- Next in thread: Doug Bell: "Re: Create 1DataTable from a Select from DataTable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|