Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Dataview-to-Datatable: A CopyTo to call my own

I wanted to copy a dataview to a datatable this afternoon and it proved an interesting case.  The data consisted of file and folder info, and I needed to group by folder name with an onitembound call to determine the count of files by folder.  The dataview was sorted, filtered, and ready to go, yet I couldn't make the leap.

A dotnet newsgroup post to "Neil" read:

Neil,

You could use something like that

1. Use RowFilter property of your DataView to filter your rows.
2. Copy all rows to array using CopyTo method of DataView.
3. Use ImportRow or LoadDataRow method of DataTable to load rows from array into DataTable

--
Val Mazur
Microsoft MVP

(Thanks Val!)  Which made great sense to me, but I kept getting datarow to datarowview mistype errors.  So I wanted to know more about this DataView CopyTo method.  The VS.NET help page was one of those lamers you occasionally encounter at

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/
frlrfSystemDataDataViewClassCopyToTopic.htm

And further Googling made me think that it was a phantom method that no one really uses.  So I ended up with the following.  The cool thing was that I discovered the datatable.select() method.  Didn't know about that at all!

Comments (0) | Post RSS RSS comment feed

Posted on 7/8/2003 8:49:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke