dcsimg
Results 1 to 3 of 3

Thread: Generic function

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Generic function

    Hi

    I have below code written on each selection of report . Each report will have different dataset & stored procedure . How i can create Generic function of below code

    Code:
    Dim data As New DataSet1.Sp_CostingDataTable
    
            con = New SqlConnection("Server=test;Database=Costing;Trusted_Connection=True;")
            con.Open()
    
            Dim adp As SqlDataAdapter = New SqlDataAdapter()
            adp.SelectCommand = New SqlCommand("Costing", con)
            adp.SelectCommand.CommandType = CommandType.StoredProcedure
            adp.Fill(data)
            Dim rds As New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", CType(data, DataTable))
            rptViewer.LocalReport.DataSources.Clear()
            rptViewer.ProcessingMode = ProcessingMode.Local
            rptViewer.LocalReport.DataSources.Add(rds)
    
            rptViewer.LocalReport.ReportPath = "D:\Costing.rdlc"
            rptViewer.LocalReport.Refresh()
            rptViewer.RefreshReport()
    Thanks
    Thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,513

    Re: Generic function

    Try this...

    Code:
    Private Sub CreateReport(ByVal data As DataTable, ByVal cmdText As String)
        Dim con As New SqlConnection("Server=test;Database=Costing;Trusted_Connection=True;")
        con.Open()
    
        Dim adp As SqlDataAdapter = New SqlDataAdapter()
        adp.SelectCommand = New SqlCommand(cmdText, con)
        adp.SelectCommand.CommandType = CommandType.StoredProcedure
        adp.Fill(data)
        Dim rds As New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", CType(data, DataTable))
        rptViewer.LocalReport.DataSources.Clear()
        rptViewer.ProcessingMode = ProcessingMode.Local
        rptViewer.LocalReport.DataSources.Add(rds)
    
        rptViewer.LocalReport.ReportPath = "D:\Costing.rdlc"
        rptViewer.LocalReport.Refresh()
        rptViewer.RefreshReport()
    End Sub
    To call it...

    Code:
    CreateReport(New DataSet1.Sp_CostingDataTable, "Costing")

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,513

    Re: Generic function

    If you want a variable ReportPath, just add another string parameter to the signature and use the supplied string argument instead of "D:\Costing.rdlc"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width