Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / April 2006

Tip: Looking for answers? Try searching our database.

Problems Using datasetObject.DefaultView for filtering and sorting.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Rynearson - 26 Apr 2006 17:41 GMT
I am using c# and VS2003 (.Net v1.1).

I am trying to filter and / or sort a dataset and print out the results as
shown below.  I have seen several examples of using the DefaultView for the
table, but the results were sent to a UI control's datasource property.
Does anyone know how I can make use of the defaultView to retrieve either a
dataRow[] array, dataTable, or something else I could interate through and
print?

Alternatively, can anyone suggest alternat approaches to my problem?

public void process(DataTable myTable)

{

DataView myView = new DataView( myTable );

myTable.DefaultView.Sort = "TransactionCode";

myTable.DefaultView.ApplyDefaultSort = true;

foreach (DataRow currRow in myTable.Rows)

{

Console.Write ("TC " + currRow["TransactionCode"].ToString());

Console.Write (" / TY " + currRow["TransactionYear"].ToString());

Console.Write (" / IY " + currRow["InstallationYear"].ToString());

Console.Write (" / IY " + currRow["TransactionCode"].ToString());

Console.WriteLine (" / TA " + currRow["TransactionCode"].ToString());

}

}

/* Table structure in XML format

<DataRecords>

<DataRecordsId>5581</DataRecordsId>

<AccountNumber>99120</AccountNumber>

<GroupNumber>00</GroupNumber>

<CompanyNumber>03</CompanyNumber>

<TransactionCode>0</TransactionCode>

<TransactionYear>1969</TransactionYear>

<InstallationYear>1921</InstallationYear>

<TransactionAmount>-1047.6000</TransactionAmount>

<AdjustedTransYear> </AdjustedTransYear>

<ClassificationData> </ClassificationData>

</DataRecords>

*/
Mark Ashton - 26 Apr 2006 22:14 GMT
You can iterate over the DataRowView in the DataView.
If you use the DefaultView, you don't need to 'new DataView'.

myTable.DefaultView.Sort = "TransactionCode";
foreach(DataRowView currRow in myTable.DefaultView) {
 Console.Write ("TC " + currRow["TransactionCode"].ToString());
 Console.Write (" / TY " + currRow["TransactionYear"].ToString());
 Console.Write (" / IY " + currRow["InstallationYear"].ToString());
 Console.Write (" / IY " + currRow["TransactionCode"].ToString());
 Console.WriteLine (" / TA " + currRow["TransactionCode"].ToString());
}

> I am using c# and VS2003 (.Net v1.1).
>
[quoted text clipped - 62 lines]
>
> */
Gary Rynearson - 27 Apr 2006 12:05 GMT
Mark

Thanks ... the approach you suggested does solve my problem.

Gary

> You can iterate over the DataRowView in the DataView.
> If you use the DefaultView, you don't need to 'new DataView'.
[quoted text clipped - 78 lines]
>>
>> */

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.