locked
run time error on crystal report in the formula filed

    Question

  • hi,
              am using formula filed in the detail field in crystal report. In formula, am using sum operation by group.when i pass values at runtiime it says following error
                    i have send the code here
     Try
    
    
                Dim cd As New OleDbCommand(" select  InvoiceNo,pdate,TinNo,vendorname,sum(totalAmount) as AMT,sum(vatamt)as VATAMT from purchase where pdate between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# group by InvoiceNo,pdate,TinNo,vendorname ", cn)
                Dim da As New OleDbDataAdapter(cd)
                Dim ds As New DataSet()
                da.Fill(ds, "a")
                Report.SetDataSource(ds.Tables("a"))
    
    
                Try
                    Dim cd1 As New OleDbCommand(" select sum(vatamt) from purchase where vat=" & 4 & " and pdate between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# group by InvoiceNo,pdate,TinNo,vendorname", cn)
                    Dim da1 As New OleDbDataAdapter(cd1)
                    da1.Fill(Dt1)
                    Report.SetParameterValue("vat4", Dt1.Rows(0).Item(0).ToString())
    
                Catch ex As Exception
                    Report.SetParameterValue("vat4", "0")
                End Try
                Try
                    Dim cd11 As New OleDbCommand(" select sum(vatamt) from purchase where vat=" & 12.5 & " and pdate between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# group by InvoiceNo,pdate,TinNo,vendorname", cn)
                    Dim da11 As New OleDbDataAdapter(cd11)
                    da11.Fill(Dt2)
                    Report.SetParameterValue("vat12.5", Dt2.Rows(0).Item(0).ToString())
                Catch ex As Exception
                    Report.SetParameterValue("vat12.5", "0")
                End Try
    
    
    
                Purchasereport.CrystalReportViewer1.ReportSource = Report
                Purchasereport.CrystalReportViewer1.Show()
                Purchasereport.Show()
            Catch ex As Exception
                MessageBox.Show("You have not purchased anything")
            End Try
            Me.Close()
        End Sub


    ERROR

    " the field name is not known
      error in file c:\docume~1\zz\locals\temp\temp_c8ab370ee......
     error in formula <AMT>
    ' sum({pur.amt},{pur.inv})'
    the field name is not known"




    any body help me?


    thanx
    • Moved by Bruce.Zhou Friday, May 15, 2009 5:51 AM move to the right forum (From:Windows Forms Data Controls and Databinding)
    Tuesday, May 12, 2009 7:25 AM

All replies

  • Hi,

    The would because the fields used in formula did not get setted when the source is specified.

    Please try check with  datasource fields at runtime.

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Saturday, May 16, 2009 6:00 AM
  • hi harrry,
                        i have checked the datasource its proper.. 


                             the same code is working in another place.
    can i have any other solutions for that..



    thanx for ur reply




    Saturday, May 16, 2009 7:18 AM
  • hi harrry,
                        i have checked the datasource its proper.. 


                             the same code is working in another place.
    can i have any other solutions for that..



    thanx for ur reply

    Saturday, May 16, 2009 7:21 AM
  • Hi,

    The same code works on other machine. You might want to create a new project with the code to see if this works.

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 18, 2009 10:15 AM
  • hi harry,



                 actually what i meant at the last msg that the same code was working in another report of the same project.can i have any other way?





    thanx for ur reply
    Wednesday, May 20, 2009 6:39 AM
  • Hi,

    Do you mean the two reports show the same contents?

    Have you tried examing the difference between the reports?
    Is the fomula setted correctly?

    Harry

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 20, 2009 6:42 AM

  • hi,
                    

     no ther r not same.but the procedure is same... the formulas are perfect
    here i have sent another code that i have used for another report.this code is wrkin properly
    Try
          
                Dim cd As New OleDbCommand("select Invoiceno,CusTin,cusname,[date],sum(rate) as rate,sum(vatamt) as vatamt from bill where [date] between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# group by invoiceno,CusTin,cusname,[date]", cn)
                Dim da As New OleDbDataAdapter(cd)
                Dim ds As New DataSet()
    
                da.Fill(ds, "a1")
                Report.SetDataSource(ds.Tables("a1"))
    
                Try
                    Dim cd1 As New OleDbCommand("select sum(vatamt) from bill where vat=" & 4 & " and date between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# ", cn)
                    Dim da1 As New OleDbDataAdapter(cd1)
                    da1.Fill(Dt)
                    Report.SetParameterValue("vat4", Dt.Rows(0).Item(0).ToString())
                Catch ex As Exception
                    Report.SetParameterValue("vat4", "0")
    
                End Try
                Try
                    Dim cd11 As New OleDbCommand("select sum(vatamt) from bill where vat=" & 12.5 & " and date between #" & DateTimePicker1.Value & "# and #" & DateTimePicker2.Value & "# ", cn)
                    Dim da11 As New OleDbDataAdapter(cd11)
                    da11.Fill(Dt1)
                    Report.SetParameterValue("vat12.5", Dt1.Rows(0).Item(0).ToString())
                Catch ex As Exception
                    Report.SetParameterValue("vat12.5", "0")
    
                End Try
    
    
                billreport.CrystalReportViewer1.ReportSource = Report
                billreport.CrystalReportViewer1.Show()
                billreport.Show()
            Catch ex As Exception
                MessageBox.Show("You have not yet billed anything")
            End Try
    
    
    
    
            Me.Close()
    this is the code which works properly




    Thursday, May 21, 2009 9:44 AM
  • The two code snippets are similar.

    Is it possible  you upload an application which can help us to reproduce the scenario?

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 21, 2009 10:10 AM
  • hi harry,


                          ok i'll upload my project n where should i upload?..can u guide me?




    thanx
    Friday, May 22, 2009 6:14 AM
  • Hi,

    You might want to upload the project to the public folder of http://skydrive.live.com.
    Then please post the link to it.

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, May 22, 2009 6:16 AM
  • hi harry,
                       i solved this problem through another way.. i have created new report with group and created formula fields thereitself..


    thank u for ur reply 
    Friday, May 29, 2009 9:58 AM