Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  How to turn a Dataview with a rowfilter into a table (Monday, January 31, 2005)




Found the following interesting discussion in the Newsgroups:

How do I turn a Dataview with a rowfilter into a table?
by:Lars Netzel

I have a Dataview with a rowfilter on and I want to create a DataTable from
that filtering!

It's because I need to set that Table as a property in a special class that
I have.. and I can't change the class to use Dataviews instead so I need to
do this

best regard
/lars


 Reply:
by:One Handed Man \( OHM - Terry Burns \)

 I think you will have to iterate through the rows and add them to a table.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .


 Reply:
by:Lars Netzel

 Yeah I found a C# Example about it that that sucked, but I got the idea and
made this!

Dim myTable As DataTable = dvCodes.Table.Clone

Dim enumCodes As IEnumerator = dvCodes.GetEnumerator

While enumCodes.MoveNext

Dim myRowView As DataRowView = enumCodes.Current

Dim newRow As DataRow = myTable.NewRow

Try

newRow("CREG_ID") = myRowView("creg_ID")

newRow("creg_regType") = myRowView("creg_regType")

newRow("creg_code") = myRowView("creg_code")

newRow("creg_text") = myRowView("creg_text")

newRow("creg_catId") = myRowView("creg_catId")

newRow("creg_unit") = myRowView("creg_unit")

myTable.Rows.Add(newRow)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End While

/Lars


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 Lars,
I find its easier to use DataTable.ImportRow to create the second table,
rather then manually copying each column. Something like:

Dim inputTable As DataTable

Dim output As DataTable = inputTable.Clone

' import based on a DataView
Dim input As DataView = dvCodes
For Each row As DataRowView In input
output.ImportRow(row.Row)
Next

' import based on a DataTable.Select
Dim input() As DataRow = inputTable.Select(filterExpression)
For Each row As DataRow In input
output.ImportRow(row)
Next

Hope this helps
Jay


 Reply:
by:Cor Ligthert

 Hi Lars,

In addition to OHM (a very slight addition),

You can also have a look at the datatable.select with the same filtering.
That gives direct a datarowcollection.

Cor








 
Previous Posts
    - Error in Remoting
    - How to access menuitem's name property of a contex...
    - Addins in vb.net
    - How to Resolve MAC addresses
    - How the order of Get/Set property is determined?
    - WIA Automation seems useless
    - WIA Automation seems useless
    - How to pass data between two forms?
    - .net remoting debug: break point doesn't stop on r...
    - How to pass Event Delegate as an argument

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland