H
Hadeel
Hi,
I'm trying to develop Dynamic reports (Add Hoc Reports) in Windows
application using VB.Net and .Net crystal Reports ( ver. 9). The user will
choose the fields he/she wants to view in the report and choose the group or
sorting field, and depending on that I will view the right fields in the
report. So I want to bind the report to a data set at RunTime , and then If
possible I want to save the report template to be viewed any time later. I
tried to use formulas in the report and then assign their values at runtime,
but it seems I'm missing some thing, because it is not working properly.
This is the code I'm adding to the form that has the Crystal report viewer ,
right after the InitializeComponent() function :
Dim crFormulaTextField1 As FormulaFieldDefinition
Dim crFormulaTextField2 As FormulaFieldDefinition
Dim crFormulaDBField1 As FormulaFieldDefinition
Dim crformulaDBField2 As FormulaFieldDefinition
Dim ds As DataSet
Dim dt As DataTable
'Field1 & Field2 are the fields the user wants to view in the 'report
ds = dsCreateDataSet("SELECT " & Field1 & "," & Field2 & "," from " &
TableName & "") ' This function returns a dataset
dt = tblCreateDataTable("SELECt " & Field1 & "," & Field2 & from " &
TableName & "") 'This function returns a datatable
crFormulas = Rpt.DataDefinition.FormulaFields
crFormulaDBField1 = crFormulas.Item(0)
crformulaDBField2 = crFormulas.Item(1)
crFormulaTextField1 = crFormulas.Item(2)
crFormulaTextField2 = crFormulas.Item(3)
'The errors start here
' pass in the database fields to be displayed
crFormulaDBField1.Text = dt.Rows(0).Item("" & Field1 & "")
crformulaDBField2.Text = dt.Rows(0).Item("" & Field2 & "")
Rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = Rpt
I would reall appreciate your help.
Thanks in advance
I'm trying to develop Dynamic reports (Add Hoc Reports) in Windows
application using VB.Net and .Net crystal Reports ( ver. 9). The user will
choose the fields he/she wants to view in the report and choose the group or
sorting field, and depending on that I will view the right fields in the
report. So I want to bind the report to a data set at RunTime , and then If
possible I want to save the report template to be viewed any time later. I
tried to use formulas in the report and then assign their values at runtime,
but it seems I'm missing some thing, because it is not working properly.
This is the code I'm adding to the form that has the Crystal report viewer ,
right after the InitializeComponent() function :
Dim crFormulaTextField1 As FormulaFieldDefinition
Dim crFormulaTextField2 As FormulaFieldDefinition
Dim crFormulaDBField1 As FormulaFieldDefinition
Dim crformulaDBField2 As FormulaFieldDefinition
Dim ds As DataSet
Dim dt As DataTable
'Field1 & Field2 are the fields the user wants to view in the 'report
ds = dsCreateDataSet("SELECT " & Field1 & "," & Field2 & "," from " &
TableName & "") ' This function returns a dataset
dt = tblCreateDataTable("SELECt " & Field1 & "," & Field2 & from " &
TableName & "") 'This function returns a datatable
crFormulas = Rpt.DataDefinition.FormulaFields
crFormulaDBField1 = crFormulas.Item(0)
crformulaDBField2 = crFormulas.Item(1)
crFormulaTextField1 = crFormulas.Item(2)
crFormulaTextField2 = crFormulas.Item(3)
'The errors start here
' pass in the database fields to be displayed
crFormulaDBField1.Text = dt.Rows(0).Item("" & Field1 & "")
crformulaDBField2.Text = dt.Rows(0).Item("" & Field2 & "")
Rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = Rpt
I would reall appreciate your help.
Thanks in advance