views:

321

answers:

3

what can I do on the reporting side, not the sql, or the c# part of the problem?

my query returns four rows, grouped by the field payment_type, then puts the results into a datatable that's connected to my report in c#.

What can I do on the report side to pull a specific row out of the datatable where payment_type="Cash" without modifying any existing sql queries or creating any new datatables?

the solution should be limited to working with the report editor only. modifying the sql query itself or creating a new datatable with the a subset of the data in my controller class cannot be part of the solution.

+2  A: 

DataTable.Select can take simple expressions like "columnname operator value":

DataRow[] rows = MyDataTable.Select("payment_type = 'Cash'");
if(rows.Length > 0)
{
    DataRow rowYouWant = rows[0];
}
Rex M
+1 .Select() ftw.
JMP
can I call Table.Select() from a report though?
kristofer
@Kristofer what do you mean by "report"? Your question title and tags say "c# datatable" - if that is not correct, can you update them to reflect what you're actually trying to do?
Rex M
The ReportViewer, apparently it's part of visual studio 2008. All the data is calculated, in a datatable, and ready for presentation. All I need to do is get a single row where payment_type = 'Cash' from the table.
kristofer
+1  A: 

DataView's RowFilter property,

dt.DefaultView.RowFilter = "payment_type='Cash'";
adatapost
A: 

There happens to be a bunch of functions available in the reporting services related to aggregating, limiting and/or rendering results from the dataset in a report.

Here's a good list of examples: http://msdn.microsoft.com/en-us/library/ms157328.aspx#ReportFunctions

Here's my solution to the situation as well.

=FormatCurrency(Sum(IIF(Fields!pay_type.Value = "Cash", Fields!empCurBal.Value, 0.0)))
kristofer