|
Step one: Add Dataset via Add New Item, etc....
Wait a short while Visual Studio does things in the background.
Step two: Configure TableAdapter in Dataset
Double-click on the dataset to make changes
Then you will see:
Click the table adapter to configure. Look at the properties for this table adapter (you may have to right-click to do so).
Click the ellipsis to add or change parameters for this table adapter.
Click add to add a new parameter, or select the parameter to work with. Make sure you remember to select the Source
column to associate this parameter with. Click Okay.
Note: The where clause of the WorkOrderTableAdapter must be modified the first time with the @WorkOrder variable.
Example:
|
Select * From WorkOrder Where WorkOrderId = @WorkOrder
|
You cannot do this until you have already entered the parameter for this table adapter.
If Visual Studio prompts you that it wants to regenerate commands, always say yes. If it does not provide this prompt, you
need to right-click the Configure menu option and complete the steps therein.
Preview the data and provide a parameter value to prove that the parameter is correctly in place. If you supply a parameter
value and clicking Preview still returns all rows, then something is wrong or missing. You need to go back to previous steps
and try again.
Now you need to test your parameter to make sure that it works.
Step three: Preview data for TableAdapter by right-click Preview Data
Right click on the TableAdapter and select ‘Preview Data’.
Enter a value for the parameter. You should see filtered data appear:
Success! Now you need to add a new XtraReport to your project.
Step four: Add a new XtraReport via Add New Item = XtraReports 7.2 Class. Wait a minute while
XtraReports does stuff behind the scenes
Step five: Click the top left corner of the report to change the report source. The image below
shows the location with a red arrow.
Drag fields from either the ToolBox...
...or from the Field List that should now appear and/or be available to you:
The advantage of selecting fields from the Field List is that XtraReports will automatically bind them for you.
If you need to create your own bound field, drag an xrLabel field over onto the design surface.
Select the xrLabel control. Look at the properties for this control to bind it to a field in your dataset table:
Once all of your fields are bound, you are ready to move on to the next step!
After you have added the ReportToolBar and ReportViewer Objects, then you can add the following code. Note that in the
example below, I am passing in a parameter off of the URL, but you could also use Session variables, etc.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rep As New WorkOrderReport(Me.Page.Request.QueryString("WorkOrder"))
Me.ReportViewer.Report = rep
End Sub
|
Now you just need to let the report know about the parameter you are passing in to your WorkOrder Report.
To do this, add a constructor method to your XtraReports report class. Open Visual Studio and load your
web application. Open the App_Code are in Solution Explorer, and find the <ReportName>.vb or <Reportname>.cs
file. Double click to open.
Insert the following code.
Public Sub New(ByVal WorkOrderId As Integer)
MyBase.New()
'This call is required by the Designer.
InitializeComponent()
Try
Dim a As New dsWorkOrderTableAdapters.WorkOrderTableAdapter
Dim b As New
dsWorkOrderTableAdapters.vwWorkOrderMaterialsListDetailsTableAdapter
Try
a.Fill(Me.dsWorkOrder1.WorkOrder, WorkOrderId)
b.Fill(Me.dsWorkOrder1.vwWorkOrderMaterialsListDetails, WorkOrderId)
Catch ex1 As Exception
End Try
End Sub
|
Build and Run!
|