Home All Groups Group Topic Archive Search About

Problems Using datasetObject.DefaultView for filtering and sorting.

Author
26 Apr 2006 4:41 PM
Gary Rynearson
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>

*/

Author
26 Apr 2006 9:14 PM
Mark Ashton
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());
}


Show quote
"Gary Rynearson" wrote:

> 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>
>
> */
>
>
>
Author
27 Apr 2006 11:05 AM
Gary Rynearson
Mark

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

Gary

Show quote
"Mark Ashton" <MarkAsh***@discussions.microsoft.com> wrote in message
news:8FD94F94-8935-4FD8-A568-751772345A02@microsoft.com...
> 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());
> }
>
>
> "Gary Rynearson" wrote:
>
>> 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>
>>
>> */
>>
>>
>>

AddThis Social Bookmark Button