Rahmat Faisal

Local GL INDC - Bali

See also: Other Geeks@INDC
How to create ReportViewer in Visual Basic
1. Create new project File-New Project , select Visual Basic Language  - windows application. Set project name ReportViewer and save project.

Create new dataset and rename this dataset with name dsReport

2. In solution explorer click dsReport.xsd, and Click Toolbox link button, and from Toolbox drag drop DataTable to dsReport.xsd.

Now, rename DataTable to DT and select DataTable and right click and add column (CategoryID, CategoryName, Description).

  

3.Add new report, in solution explorer select rpttest.rdlc, from toolbox drag and drop one textbox and one table, now from Data Sources drag and drop field in table (Details).And now, time is to set parameter. Select rpttest.rdlc, in Properties-ReportParameters, Add the Title parameter and click OK.

 

4.      Select form1 from solution explorer, open toolbox and drag and drop one button, textbox and ReportViewer. Rename controls:

 

Control Name

Name

Text

Button

btnOpenReport

Fill Report

TextBox

txtParameter

This is a test …

ReportViewer

Rpt

 

 

 

import namespaces

 

Imports System.Data.SqlClient

Imports Microsoft.Reporting.WinForms

Copy this code, and call this procedure. I use Northwind database

 

Sub openReport()

        Dim strSQL As String

        strSQL = "SELECT CategoryID, CategoryName, Description  FROM Northwind.dbo.Categories"

        'Create connection

        Dim cn As New SqlConnection("Connectionstring")

        cn.Open()

        'Create DataAdapter

        Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, cn)

        'create dataset

        Dim ds As DataSet = New DataSet

        'fill dataset

        da.Fill(ds)

        'set report

        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewer.rptTest.rdlc"

        'set Datasource report

        Dim DataSource As New ReportDataSource("dsReport_DT", ds.Tables(0).DefaultView)

        ReportViewer1.LocalReport.DataSources.Add(DataSource)

        'set parameter from form to report

        Dim paramList As New Generic.List(Of ReportParameter)

        paramList.Add(New ReportParameter("Title", Me.txtParameter.Text, False))

        ReportViewer1.LocalReport.SetParameters(paramList)

        'Refresh report

        Me.ReportViewer1.RefreshReport()

    End Sub

 

Source : http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/thread/8e9ee276-5821-414b-9e64-5fad8ece6af4 

Share this post: | | | |
Published Monday, April 27, 2009 4:15 AM by Rahmat.Faisal

Comments

No Comments