G
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>
*/
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>
*/