Reputation: 25799
I have a strongly-typed DataTable
returned in a strongly-typed DataSet
from a database query. The DataSet
is subsequently passed to a ReportViewer
to display a chart based on some aspects of the data.
I've added an extra column to the dataset and I'm looping through the table calculating a value for this new column based on one of the columns returned from the database.
The calculated column is a single byte value which is simply the first element of another column which is an array of bytes.
foreach (ReportData.EventRangeRow row in ReportData.EventRange)
{
byte[] analysis = (byte[]) row[ReportData.EventRange.analysisColumn];
row[ReportData.EventRange.first_analysisColumn] = analysis[0];
}
Obviously my solution works but is a bit unwieldy, so I was wondering whether anyone could suggest a way of either automatically calculating the column as part of the typed dataset or if not, a linq statement which would achieve the same.
Thanks!
Upvotes: 0
Views: 919
Reputation: 1536
You can do many calculations on the report itself, instead of extending your Dataset.
Let's say you have a datasource "MyDataTable" connected to your report. Then drag a textbox onto the report and right click on it and then choose Expression and you get a nice window for writing expressions with lots of examples
One aggregate function could be... =First(Fields!MyColumn.Value, "MyDataTable")
Check the examples in the window under the category "Common Functions -> Aggregate"
Upvotes: 1