Pregunta

I am developing a project using VB2008 and Crystal Reports 11.5. I have added new crystal report to the project and it is working fine with the folowing code.

 Dim ds As New DataSet
    mysqlDataAdapter1 = New MySqlDataAdapter("SELECT * from client_reg where c_qid='" & TextBox2.Text & "'", SQLConnection)
    mysqlDataAdapter1.Fill(ds, "client_reg")
    ds.WriteXml(CurDir() + "\work_order.xml", XmlWriteMode.WriteSchema)

Dim cryRpt As New work_order '// this is my rpt file in project
   rpt_view.CrystalReportViewer1.ReportSource = cryRpt '// rpt_view is the form with empty report viewer
   rpt_view.CrystalReportViewer1.Refresh()
   rpt_view.CrystalReportViewer1.RefreshReport()
   rpt_view.Show()

Now I want to change the XML file location dynamically as follows;

ds.WriteXml("C:\new\bin\work_order.xml", XmlWriteMode.WriteSchema)

How can I change the RPT datasource to new path???

Thank you,

Sameera

¿Fue útil?

Solución

Try Something like : Create Property called:

Public Property ds() As DataSet
    Get
        Return ViewState("ds")
    End Get
    Set(ByVal value As DataSet)
        ViewState("ds") = value
    End Set
End Property

Then set report datasource to be the dataset

 Public Sub BindReport(ByVal Id As String)
    ds.WriteXml("C:\new\bin\work_order.xml", XmlWriteMode.WriteSchema)
    cryRpt.SetDataSource(ds)

    rpt_view.ReportSource = cryRpt
    If rblFormat.SelectedValue = 1 Then
                  cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
    Else
        cryRpt.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "ExportedReport")
    End If

Call This method at the button event

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top