By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,745 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,745 IT Pros & Developers. It's quick & easy.

Create 1DataTable from a Select from DataTable

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Doug,

Is there any reason that don't you use the currencymanager.position for your
start point and use the underlaying table from the datagrid to do the
filling of your new datatable until the rows to do are reached?

Cor
"Doug Bell" <dug@bigpond>
..
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

Nov 21 '05 #2

P: n/a
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:%2****************@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

Nov 21 '05 #3

P: n/a
Dough,

I get from the message from Jay the idea that what I did below is something
as you wanted to do

\\\This sample needs a form with 2 datagrids
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = createDS.Tables(0)
Dim mynewtable As DataTable = _
DirectCast(DataGrid1.DataSource, DataTable).Clone
Dim myrows As DataRow() = DirectCast(DataGrid1.DataSource, _
DataTable).Select("Numbers > 5")
For Each dr As DataRow In myrows
mynewtable.ImportRow(dr)
Next
DataGrid2.DataSource = mynewtable
End Sub
'Bellow only to create a datatable in a dataset
Public Function createDS() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Numbers", GetType(System.Int32))
dt.Columns.Add("Characters")
For i As Integer = 0 To 10
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
Return ds
End Function
///
I hope this helps?

Cor

"Doug Bell" <dug@bigpond>
..
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

Nov 21 '05 #4

P: n/a
Dough,

I get from the message from Jay the idea that what I did below is something
as you wanted to do

\\\This sample needs a form with 2 datagrids
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = createDS.Tables(0)
Dim mynewtable As DataTable = _
DirectCast(DataGrid1.DataSource, DataTable).Clone
Dim myrows As DataRow() = DirectCast(DataGrid1.DataSource, _
DataTable).Select("Numbers > 5")
For Each dr As DataRow In myrows
mynewtable.ImportRow(dr)
Next
DataGrid2.DataSource = mynewtable
End Sub
'Bellow only to create a datatable in a dataset
Public Function createDS() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Numbers", GetType(System.Int32))
dt.Columns.Add("Characters")
For i As Integer = 0 To 10
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
Return ds
End Function
///
I hope this helps?

Cor

"Doug Bell" <dug@bigpond>
..
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

Nov 21 '05 #5

P: n/a
Cor,
I am not using the Currency Manager because I am filling the Details Form
from a temporary data source (DataTable). I am doing this so that the Users
can make changes to the Details Form and then if they decide not to proceed
they close the form and the changes are discarded. If the changes are valid
then they will be saved from the Temporary Table into a 3rd Table (DataSet),
saved to an XML File and then pushed up into several Tables in the DB2
Database.

Doug

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
Doug,

Is there any reason that don't you use the currencymanager.position for your start point and use the underlaying table from the datagrid to do the
filling of your new datatable until the rows to do are reached?

Cor
"Doug Bell" <dug@bigpond>
.
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


Nov 21 '05 #6

P: n/a
Cor,
I am not using the Currency Manager because I am filling the Details Form
from a temporary data source (DataTable). I am doing this so that the Users
can make changes to the Details Form and then if they decide not to proceed
they close the form and the changes are discarded. If the changes are valid
then they will be saved from the Temporary Table into a 3rd Table (DataSet),
saved to an XML File and then pushed up into several Tables in the DB2
Database.

Doug

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
Doug,

Is there any reason that don't you use the currencymanager.position for your start point and use the underlaying table from the datagrid to do the
filling of your new datatable until the rows to do are reached?

Cor
"Doug Bell" <dug@bigpond>
.
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


Nov 21 '05 #7

P: n/a
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]" <Ja************@msn.com> wrote in message
news:%2******************@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:%2****************@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


Nov 21 '05 #8

P: n/a
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]" <Ja************@msn.com> wrote in message
news:%2******************@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:%2****************@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


Nov 21 '05 #9

P: n/a
Jay,

Thanks again, it is working. It is just as you said, I was clearing out the
parent DataTable.
My messagebox was showing 428 records but I must have been testing that
before the clear statement.

Thanks
Doug

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2******************@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:%2****************@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


Nov 21 '05 #10

P: n/a
Jay,

Thanks again, it is working. It is just as you said, I was clearing out the
parent DataTable.
My messagebox was showing 428 records but I must have been testing that
before the clear statement.

Thanks
Doug

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2******************@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:%2****************@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


Nov 21 '05 #11

P: n/a
Hi Cor,
'Doug' no 'h'
Thanks
I have it working this morning with Jay & your assistance.
Delivery is overdue and I am slowly coming to grips with Dot Net.

Doug

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OF**************@TK2MSFTNGP14.phx.gbl...
Dough,

I get from the message from Jay the idea that what I did below is something as you wanted to do

\\\This sample needs a form with 2 datagrids
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = createDS.Tables(0)
Dim mynewtable As DataTable = _
DirectCast(DataGrid1.DataSource, DataTable).Clone
Dim myrows As DataRow() = DirectCast(DataGrid1.DataSource, _
DataTable).Select("Numbers > 5")
For Each dr As DataRow In myrows
mynewtable.ImportRow(dr)
Next
DataGrid2.DataSource = mynewtable
End Sub
'Bellow only to create a datatable in a dataset
Public Function createDS() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Numbers", GetType(System.Int32))
dt.Columns.Add("Characters")
For i As Integer = 0 To 10
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
Return ds
End Function
///
I hope this helps?

Cor

"Doug Bell" <dug@bigpond>
.
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


Nov 21 '05 #12

P: n/a
Hi Cor,
'Doug' no 'h'
Thanks
I have it working this morning with Jay & your assistance.
Delivery is overdue and I am slowly coming to grips with Dot Net.

Doug

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OF**************@TK2MSFTNGP14.phx.gbl...
Dough,

I get from the message from Jay the idea that what I did below is something as you wanted to do

\\\This sample needs a form with 2 datagrids
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = createDS.Tables(0)
Dim mynewtable As DataTable = _
DirectCast(DataGrid1.DataSource, DataTable).Clone
Dim myrows As DataRow() = DirectCast(DataGrid1.DataSource, _
DataTable).Select("Numbers > 5")
For Each dr As DataRow In myrows
mynewtable.ImportRow(dr)
Next
DataGrid2.DataSource = mynewtable
End Sub
'Bellow only to create a datatable in a dataset
Public Function createDS() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Numbers", GetType(System.Int32))
dt.Columns.Add("Characters")
For i As Integer = 0 To 10
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(i).ItemArray = _
(New Object() {i.ToString, ChrW(i + 65)})
Next
Return ds
End Function
///
I hope this helps?

Cor

"Doug Bell" <dug@bigpond>
.
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


Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.