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
|
0 Comments:
Post a Comment
<< Home