DEBASIS BAG

DEBASIS BAG

  • NA
  • 1
  • 2.2k

Generate Report through ReportViwer using Code

Aug 23 2012 3:51 AM
Dear Sir,

I have project on vb.net 2010 platform. I know how to generate a report through reportviewer in design mode. But I want to develop using code.

I want to create connection,sqlCommand, dataset, tableAdapter, table etc through code. I have already designed table and binded with rdlc.

I need to make connection through code and filled up dataset through sql command and tableAdapter. later I will display through reprotviewer.

In this scenario, I need a sample project so that I can followup..

I have already developed but it was not working. this code i am pasting below: Please have a look.


imports Microsoft.Reporting.WinForms

 

Public Class Form1

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim ds As New WindowsApplication1.DataSet1

        Dim rds As Microsoft.Reporting.WinForms.ReportDataSource

 

        Dim tblAdp As SqlClient.SqlDataAdapter

        Dim con As SqlClient.SqlConnection

        Dim cmd As SqlClient.SqlCommand

        Dim str = "Server=localhost;Database=NH0910;UID=;Password=;Trusted_Connection=True"

        con = New SqlClient.SqlConnection(str)

        Dim sql = "SELECT * FROM VENDOR"

        cmd = New SqlClient.SqlCommand(sql, con)

        cmd.CommandType = CommandType.Text

        tblAdp = New SqlClient.SqlDataAdapter(cmd)

        tblAdp.Fill(ds.tbl)

 

        Me.ReportViewer1.RefreshReport()

        Me.ReportViewer1.Reset()

        Me.ReportViewer1.LocalReport.Dispose()

        rds = New Microsoft.Reporting.WinForms.ReportDataSource("Table1", ds.Tables(0))

        Me.ReportViewer1.LocalReport.DataSources.Clear()

        Me.ReportViewer1.LocalReport.DataSources.Add(rds)

        Me.ReportViewer1.LocalReport.ReportPath = "C:\Documents and Settings\m3\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Report1.rdlc"

        Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)

        'ReportViewer1.Show()

    End Sub

End Class 

when I am running then it's giving error like "An error occurred  during local report processing.  An error occurred  during local report processing. Dataset1"
In design mode I already created Dataset1 and table.