Dataview into new datatable

  • Thread starter Sjaakie Helderhorst
  • Start date
S

Sjaakie Helderhorst

Hi,

I've come a stage that I'm feeling an absolute idiot.
Struggling with this issue for days and can't find a suitable answer.

Have this dataset which 'amount' value can be updated. Need to send all
records with 'amount > 0' to a webservice as a Datatable. (Ignorant as I
might be) I Dim a new DataView (rowfilter 'amount > 0') and copy this into a
new datatable:


dv = New DataView(ds.Tables("Items"), _
"amount > 0", _
"barcode", _
DataViewRowState.CurrentRows)

Dim dt As New DataTable("Result")
dt = dv.Table.Copy
sendDS.Tables.Add(dt)

However, sending this datatable (dt) to a webservice will send the entire
source dataset (= huge)

What am I doing wrong ...
Is there a more suitable way of achieving this!?

Thanks in advance.
 
M

Miha Markic [MVP C#]

Hi Sjaakie,

DataView doesn't actually filter table - it only shows filtered records.
You might use DataTable.Select method which will return you DataRow[] array
or you might manually filter a copy of table (use Rows.Remove to remove the
unnecessary rows).
 
S

Sjaakie Helderhorst

Thank you, I'll use DataTable.Select instead.

Miha Markic said:
Hi Sjaakie,

DataView doesn't actually filter table - it only shows filtered records.
You might use DataTable.Select method which will return you DataRow[] array
or you might manually filter a copy of table (use Rows.Remove to remove the
unnecessary rows).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Sjaakie Helderhorst said:
Hi,

I've come a stage that I'm feeling an absolute idiot.
Struggling with this issue for days and can't find a suitable answer.

Have this dataset which 'amount' value can be updated. Need to send all
records with 'amount > 0' to a webservice as a Datatable. (Ignorant as I
might be) I Dim a new DataView (rowfilter 'amount > 0') and copy this
into
a
new datatable:


dv = New DataView(ds.Tables("Items"), _
"amount > 0", _
"barcode", _
DataViewRowState.CurrentRows)

Dim dt As New DataTable("Result")
dt = dv.Table.Copy
sendDS.Tables.Add(dt)

However, sending this datatable (dt) to a webservice will send the entire
source dataset (= huge)

What am I doing wrong ...
Is there a more suitable way of achieving this!?

Thanks in advance.
 

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