1c06f58183b056e690e1ddceb84dc0bdd2aefd36
FAQ/ProcessDataSet.md
| ... | ... | @@ -6,6 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | The ``ProcessDataSet`` method is useful when you want to use post-processing in your application. This method should be overridden in your global.asax file. |
| 8 | 8 | |
| 9 | +```csharp |
|
| 9 | 10 | public class CustomAdHocConfig : DatabaseAdHocConfig |
| 10 | 11 | { |
| 11 | 12 | public override void ProcessDataSet(DataSet ds, string reportPart) |
| ... | ... | @@ -13,6 +14,7 @@ public class CustomAdHocConfig : DatabaseAdHocConfig |
| 13 | 14 | // Put your code here |
| 14 | 15 | } |
| 15 | 16 | } |
| 17 | +``` |
|
| 16 | 18 | |
| 17 | 19 | The first parameter is the System.Data.DataSet retrieved from the database. It is called "ds" here, but it can be named anything as long as the datatype remains the same. The second parameter is the name of the report in the ReportSet. For example, if part of your report is a grid named "Detail" and part of your report is a pie chart named "Chart", you can reference the grid part of your report by checking if ReportPart = "Detail". With that part of the report captured, you can manipulate it how you want and display the results. |
| 18 | 20 | |
| ... | ... | @@ -30,27 +32,53 @@ Now let's add some extra code to the CustomAdHocConfig class: |
| 30 | 32 | ```csharp |
| 31 | 33 | public override void ProcessDataSet(DataSet ds, string reportPart) |
| 32 | 34 | { |
| 33 | - // We want to alter only "Detail" part of the report set |
|
| 34 | - if (reportPart == "Detail") |
|
| 35 | - { |
|
| 36 | - if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) |
|
| 37 | - { |
|
| 38 | - // Iterate through columns to find column with name "Ship Region" |
|
| 39 | - for (int index = 0; index < ds.Tables[0].Columns.Count; index++) |
|
| 40 | - if (ds.Tables[0].Columns[index].ColumnName == "Ship Region") |
|
| 41 | - { |
|
| 42 | - foreach (DataRow row in ds.Tables[0].Rows) |
|
| 43 | - if (row[index].ToString() == "CA") |
|
| 44 | - row[index] = "California"; |
|
| 45 | - // There can be only one column with a specific name, |
|
| 46 | - // so we can leave the cycle as soon as we find it |
|
| 47 | - break; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 35 | + // We want to alter only "Detail" part of the report set |
|
| 36 | + if (reportPart == "Detail") |
|
| 37 | + { |
|
| 38 | + if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) |
|
| 39 | + { |
|
| 40 | + // Iterate through columns to find column with name "Ship Region" |
|
| 41 | + for (int index = 0; index < ds.Tables[0].Columns.Count; index++) |
|
| 42 | + { |
|
| 43 | + if (ds.Tables[0].Columns[index].ColumnName == "Ship Region") |
|
| 44 | + { |
|
| 45 | + foreach (DataRow row in ds.Tables[0].Rows) |
|
| 46 | + { |
|
| 47 | + if (row[index].ToString() == "CA") |
|
| 48 | + row[index] = "California"; |
|
| 49 | + } |
|
| 50 | + // There can be only one column with a specific name, |
|
| 51 | + // so we can leave the cycle as soon as we find it |
|
| 52 | + break; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 51 | 57 | } |
| 52 | 58 | ``` |
| 53 | 59 | |
| 60 | +```visualbasic |
|
| 61 | +Public Overrides Sub ProcessDataSet(ByVal ds As DataSet, ByVal reportPart As String) |
|
| 62 | + 'We want to alter only "Detail" part of the report set |
|
| 63 | + If reportPart = "Detail" Then |
|
| 64 | + If ds IsNot Nothing AndAlso ds.Tables.Count > 0 AndAlso ds.Tables(0) IsNot Nothing AndAlso ds.Tables(0).Rows.Count > 0 Then |
|
| 65 | + 'Iterate through columns to find column with name "Ship Region" |
|
| 66 | + For index As Integer = 0 to ds.Tables(0).Columns.Count - 1 |
|
| 67 | + If ds.Tables(0).Columns(index).ColumnName = "Ship Region" Then |
|
| 68 | + For Each row As DataRow In ds.Tables(0).Rows |
|
| 69 | + If row(index).ToString() = "CA" Then |
|
| 70 | + row(index) = "California" |
|
| 71 | + 'There can be only one column with a specific name, |
|
| 72 | + 'so we can leave the cycle as soon as we find it |
|
| 73 | + break; |
|
| 74 | + End If |
|
| 75 | + Next |
|
| 76 | + End If |
|
| 77 | + Next |
|
| 78 | + End If |
|
| 79 | + End If |
|
| 80 | +End Sub |
|
| 81 | +``` |
|
| 54 | 82 | And after implementing post-prosessor the result will be: |
| 55 | 83 | |
| 56 | 84 |  |