locked
Doubt in Local Reports RRS feed

  • Question

  •  

    Hi all i am using following code to Generate Local Reports.I have one web form contains drop down list,it contains 'Yes' and 'No' values.I have to display different reports depend on selected criteria.If i select 'Yes' and click on submit button i am getting the report in PDF format,If i click back button and select 'No'  and click on Submit button i am getting the following error:I designed two reports separately and created two separate data sources.

     

    • An error has occurred during report processing.

      • A data source instance has not been supplied for the data source "VehicleAssetRegisterFirst_DataTable1".

       

       

       

       

      Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

      Dim warnings As Warning() = Nothing

      Dim streamids As String() = Nothing

      Dim mimeType As String = Nothing

      Dim encoding As String = Nothing

      Dim extension As String = Nothing

      Dim bytes As Byte()

      Dim FolderLocation As String

      Dim Flag As String

      Dim filepath As String

      Dim sql As String

       

      Dim count As Integer

      If ddlInspected.SelectedValue = "Yes" Then

      FolderLocation = Path.GetTempPath

      filepath = FolderLocation & "VehicleAssetRegister1.pdf"

      File.Delete(filepath)

      ReportViewer1.ProcessingMode = ProcessingMode.Local

      sql = "SELECT V.VEHICLESTATUSNAME,D.DEPARTMENTNAME,P.ENGINENO,P.CHASISNO,P.ENGINENOVERIFIED,P.CHASISNOVERIFIED,P.COLORVERIFIED,P.LICENCEDISC," & _

      " P.LICENCEDISCEXPDATE,P.ODOMETERREADING,P.CONDITIONOFVEHICLE,C.COLORNAME,P.RETROREFLECTIVETYPE,P.WHEELFLAPS,P.RECOMMENDEDFORBOS FROM " & _

      " TFMS_PHYSICALVERIFICATION P LEFT JOIN TFMS_VEHICLESTATUS_MASTER V ON V.VEHICLESTATUSID=P.STATUS LEFT JOIN TFMS_DEPARTMENT_MASTER D " & _

      " ON D.DEPARTMENTID=P.DEPARTMENTID LEFT JOIN TFMS_COLOR_MASTER C ON C.COLORID=P.NUMBERPLATECOLOR"

      If ddlDeptName.SelectedValue <> "" Then

      sql = sql & " WHERE D.DEPARTMENTID='" + ddlDeptName.SelectedValue + "'"

      Flag = "S"

      End If

      If ddlStatus.SelectedValue <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND V.VEHICLESTATUSID='" + ddlStatus.SelectedValue + "'"

      Else

      sql = sql & " WHERE V.VEHICLESTATUSID='" + ddlStatus.SelectedValue + "'"

      Flag = "S"

      End If

      End If

      If txtFromdate.Value <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND TO_CHAR(P.DATEINSPECTED,'DD-MON-YY')>=TO_DATE('" + txtFromdate.Value + "','DD-MON-YY')"

      Else

      sql = sql & " WHERE TO_CHAR(P.DATEINSPECTED,'DD-MON-YY')>=TO_DATE('" + txtFromdate.Value + "','DD-MON-YY')"

      Flag = "S"

      End If

      End If

      If txtTodate.Value <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND TO_CHAR(P.DATEINSPECTED,'DD-MON-YY')<=TO_DATE('" + txtTodate.Value + "','DD-MON-YY')"

      Else

      sql = sql & " WHERE TO_CHAR(P.DATEINSPECTED,'DD-MON-YY')<=TO_DATE('" + txtTodate.Value + "','DD-MON-YY')"

      End If

      End If

      Else

      FolderLocation = Path.GetTempPath

      filepath = FolderLocation & "VehicleAssetRegister2.pdf"

      File.Delete(filepath)

      ReportViewer1.ProcessingMode = ProcessingMode.Local

       

      sql = "SELECT AR.KZNREGNO,AR.VEHICLEREGNO,D.DEPARTMENTNAME,AR.ENGINENO,AR.CHASISNO,V.VEHICLESTATUSNAME FROM TFMS_ASSETREGISTER AR LEFT JOIN " & _

      " TFMS_DEPARTMENT_MASTER D ON D.DEPARTMENTID=AR.DEPARTMENTID LEFT JOIN TFMS_VEHICLESTATUS_MASTER V ON V.VEHICLESTATUSID=AR.VEHICLESTATUS"

      If ddlDeptName.SelectedValue <> "" Then

      sql = sql & " WHERE D.DEPARTMENTID='" + ddlDeptName.SelectedValue + "'"

      Flag = "S"

      End If

      If ddlStatus.SelectedValue <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND AR.VEHICLESTATUS='" + ddlStatus.SelectedValue + "'"

      Else

      sql = sql & " WHERE AR.VEHICLESTATUS='" + ddlStatus.SelectedValue + "'"

      Flag = "S"

      End If

      End If

      If txtFromdate.Value <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND TO_CHAR(AR.ASSESTDATE,'DD-MON-YY')>=TO_DATE('" + txtFromdate.Value + "','DD-MON-YY')"

      Else

      sql = sql & " WHERE TO_CHAR(AR.ASSESTDATE,'DD-MON-YY')>=TO_DATE('" + txtFromdate.Value + "','DD-MON-YY')"

      Flag = "S"

      End If

      End If

      If txtTodate.Value <> "" Then

      If Not Flag = "" Then

      sql = sql & " AND TO_CHAR(AR.ASSESTDATE,'DD-MON-YY')<=TO_DATE('" + txtTodate.Value + "','DD-MON-YY')"

      Else

      sql = sql & " WHERE TO_CHAR(AR.ASSESTDATE,'DD-MON-YY')<=TO_DATE('" + txtTodate.Value + "','DD-MON-YY')"

      End If

      End If

       

      End If

      sql = sql & " ORDER BY D.DEPARTMENTID"

      myDataSet = GetVehicleAssetRegisterCount(sql)

      count = myDataSet.Tables("DataTable1").Rows.Count

      If count > 0 Then

      lblNoRecords.Visible = False

      ReportViewer1.Visible = True

      Dim rep As LocalReport = ReportViewer1.LocalReport

       

       

      If ddlInspected.SelectedValue = "Yes" Then

      'Dim ds1 As New ReportDataSource()

      rep.ReportPath = System.AppDomain.CurrentDomain.BaseDirectory & "Reports\VehicleAssetRegisterFirst.rdlc"

      ds.Name = "VehicleAssetRegisterFirst_DataTable1"

      ds.Value = myDataSet.Tables("DataTable1")

      ReportViewer1.LocalReport.DataSources.Clear()

      rep.DataSources.Add(ds)

       

      ' To View in PDF Format

      bytes = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

      Dim fs As New FileStream(FolderLocation & "VehicleAssetRegister1.PDF", FileMode.Create)

      fs.Write(bytes, 0, bytes.Length)

      fs.Close()

      fs = File.Open(filepath, FileMode.Open)

      Dim bytfile(fs.Length) As Byte

      fs.Read(bytfile, 0, fs.Length)

      fs.Close()

      Response.ContentType = "application/pdf"

      Response.AddHeader("Content-disposition", "inline;filename=VehicleAssetRegister1.pdf")

      Response.BinaryWrite(bytfile)

      Response.End()

      ReportViewer1.LocalReport.Refresh()

      Else

      rep.ReportPath = System.AppDomain.CurrentDomain.BaseDirectory & "Reports\VehicleAssetRegisterSec.rdlc"

      ds.Name = "VehicleAssetRegisterSec_DataTable1"

      ds.Value = myDataSet.Tables("DataTable1")

      ReportViewer1.LocalReport.DataSources.Clear()

      rep.DataSources.Add(ds)

      ' To View in PDF Format

      bytes = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

      Dim fs As New FileStream(FolderLocation & "VehicleAssetRegister2.PDF", FileMode.Create)

      fs.Write(bytes, 0, bytes.Length)

      fs.Close()

      fs = File.Open(filepath, FileMode.Open)

      Dim bytfile(fs.Length) As Byte

      fs.Read(bytfile, 0, fs.Length)

      fs.Close()

      Response.ContentType = "application/pdf"

      Response.AddHeader("Content-disposition", "inline;filename=VehicleAssetRegister2.pdf")

      Response.BinaryWrite(bytfile)

      Response.End()

      ReportViewer1.LocalReport.Refresh()

      End If

      Else

      ReportViewer1.Visible = False

      lblNoRecords.Visible = True

      lblNoRecords.Text = "No Records Found"

      End If

      End Sub

       

       

      Please Help me.

       

       

       

    Monday, September 15, 2008 5:40 AM

Answers

  • Hi all

    I solved my problem my self,Just i used two different Report Viewer Controls for two different data sources and two different rdlc files.

    k

    By

     

    Thursday, September 18, 2008 8:55 AM