1. In the
Item
2. In the Categories area of the Add New Item dialog box, expand the folder and select
Solution Explorer, right-click the project name, point to Add, and click Add New.Data
3. In the Templates area, select
4. Accept the default name
Solutions Explorer, click on Dataset1.xsd file, if now already the active view.Server Explore, on the right connect to SQL Server and drill down to
This creates a new schema file that will be used to generate a strongly typed dataset. The
schema file will be displayed in ADO.NET Dataset designer.
5. In the
6. From the
Northwind Database.
7. Highlight the Table Customers (or stored procedure if desired) and drag and drop it on
the Interface of Dataset1.xsd. Dataset1.xsd should now be displayed in the Dataset tab
as under
This creates a dataset object and contains only a description of the database based on the
schema in Dataset1.xsd. It does not contain the actual data.
Connecting Report to an ADO.NET Dataset Object
From ADO.NET Dataset Object you can add tables to Crystal Report using Database Expert in
Crystal Report Designer.
To create a new report and connect it to Dataset object which contains description for
Customers table in Northwind database
1. In the Visual Studio .NET
shortcut menu.
2. Point to
3. In the Add New Item dialog box, select
Solution Explorer, right-click your project to display theAdd and click Add New Item.Crystal Report from the Templates area. ClickOpen4.
5. You can choose from any of the options provided in Crystal Report Gallery. But for the
purpose of this walkthrough choose 6. On
7. Right click in the Report Designer, point to
8. You’ll be presented with
9. In the Database Expert wizard, expand the
Datasets 10. If you now drill down
Customers table and all its fields
11. Drag and drop the fields onto the report and format them as required.
Pushing data into DataSet object and binding report to Windows Forms Viewer
In order to display actual data in the report, you should fill the dataset object with the data before
you bind the report to Windows Forms Viewer. You should do this in the corresponding source file
for Windows Form.
1. Drag and drop
CrystalReportViewer control on Form1 and set the DisplayGroupTreeproperty to
2. Accept the default name as
3. Open
Private Sub
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase
.LoadDim
rpt As New CrystalReport1() 'The report you created.Dim
myConnection As SqlConnectionDim
MyCommand As New SqlCommand()Dim
myDA As New SqlDataAdapter()Dim
myDS As New Dataset1() 'The DataSet you created.Try
myConnection =
& _
"Initial Catalog=northwind;")
MyCommand.Connection = myConnection
MyCommand.CommandText = "SELECT * FROM Customers"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "Customers")
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
New SqlConnection("Data Source=localhost;Integrated Security=SSPI;"Catch
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Excep As ExceptionEnd Try
End Sub






No comments:
Post a Comment