Crystal Report

Hello friends, I have a invoice form that contains some billing info (i.e. textbox, dropdown field etc...) and i have a calculate button in it that calculate the sum total of the relevant fields. so i want to print the data in crystal report. i have vs 2008 that already inbuilt CR. it'll prints only the data that put in billing field not all the database field. so plz help me.

Comments

  • seancampbellseancampbell Pennsylvania, USA
    Please paste your source code in a "code" block.
  • my code is as here under:
    [code]
    Try
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Billing").ConnectionString)

    Dim mmd As SqlCommand = conn.CreateCommand

    mmd.CommandType = CommandType.Text

    mmd.CommandText = "Select * From Bill"

    Using conn

    conn.Open()
    Dim da As New SqlDataAdapter(mmd)
    Dim ds As New SqlCommandBuilder(da)

    Dim mytable As New DataTable("Billing")

    da.Fill(mytable)

    mytable.Rows.Add(txtSerial.Text.Trim, cmdName.Text.Trim, dtCrDate.Text.Trim, cmbSrRate.Text.Trim, txtShrQty.Text.Trim, txtShrAmount.Text.Trim, cmbSrrRate.Text.Trim, txtShrrQty.Text.Trim, txtShrrAmount.Text.Trim, _
    cmbptRate.Text.Trim, txtPtQty.Text.Trim, txtPtAmount.Text.Trim, cmbptRRate.Text.Trim, txtPtRQty.Text.Trim, txtPtRAmount.Text.Trim, txtCoatRate.Text.Trim, txtCoatQty.Text.Trim, txtCoatAmount.Text.Trim, txtSafariRate.Text.Trim, txtSafariQty.Text.Trim, txtSafariAmount.Text.Trim, _
    txtKurtaRate.Text.Trim, txtKurtaQty.Text.Trim, txtKurtaAmount.Text.Trim, txtPjmRate.Text.Trim, txtPjmQty.Text.Trim, txtPjmAmount.Text.Trim, _
    DtDLvDate.Text.Trim, txtgrdTotal.Text.Trim)

    da.Update(mytable)
    mmd.ExecuteNonQuery()
    conn.Close()

    End Using

    MessageBox.Show("Do You want to Print the Bill", caption:="Print Bill")
    Catch ex As Exception
    MessageBox.Show("An Error has Occured: " + ex.Message.ToString + vbCritical, vbCrLf)
    End Try
    [/code]

    The matter is that i creating a small billing project that contains Invoice fields. Firstly i save all the data in my database, then after i added the messagebox method in it to display "Do you want to print the data". so now the trick is that the crystal report print only last Invoice record which i saved in the database i.e. LIFO method.

    thank u
  • seancampbellseancampbell Pennsylvania, USA
    Maybe I am not understanding what you are asking? From reading your first post, It sounds like you have a Crystal Report built, but it is not returning all of the information you want it to... You are asking for some help to get that report working correctly?

    If that is not what you were asking, please restate what you need clearly.

    The code that you provided is to insert a record into a database table. Do you already have code written to print a crystal report, if so you will need to post that, we can work off of that to get you a solution.

    If you are asking for help building a crystal report to display the last item added to the database, I do not know much about crystal report building, but I know Databases enough to help you with that.

    Add a field to the Database Table called "Creation_Time" or something similar "Added_Date" "Added_Time" and set it to be datatype "Date/Time". When you insert a record to the database, set the Creation Time = Now

    [code]
    Dim dtNow as Date = Now
    MessageBox.Show(dtNow)
    [/code]

    In your crystal report, when you query the data, your SQL should look like this:

    "SELECT TOP 1 * FROM MyDataTable ORDER BY Creation_Time DESC"

    This line returns the TOP 1 (1 result) record, with all fields (*), From the MyDataTable table, ordering the results by Creation_Time with the highest value (most recent date) at the top of the list, Ordered Descending.

    Hope this helps,
    Sean C
  • Hi Thanx for ur reply, Now i added Crystal Report code.
    [code]
    Dim cryRpt As New ReportDocument
    With cryRpt
    Dim str As String = "Report Directory/bill.RPT"
    .SetDataSource(mytable)
    .Load(str)
    CrystalReportViewer1.ReportSource = cryRpt
    CrystalReportViewer1.Refresh()
    End With
    [/code]

    but the following error occurs: Invalid Report File Path
  • seancampbellseancampbell Pennsylvania, USA
    [code]
    Dim str As String = "Report Directory/bill.RPT"
    [/code]

    Firstly, you used the wrong slash in your path (use "/" for web addresses and unix, use "" for Windows Paths)

    Secondly, This needs to be the fully qualified path of the file you are trying to load... for instance, I want to open "SeanCampbell.RPT" and it is in a folder in "program files" my code would look like this:

    [code]
    Dim str as String = "C:Program FilesSome Folder I Just MadeSeanCampbell.RPT"
    [/code]

    If you want to load a file that you have added to the same folder the application is running in, u don't have to designate the full path:

    [code]
    Dim Str as String = "Sean.RPT"
    [/code]
    When I go to load this file, it will look in this path:
    C:Documents and SettingsSeanCampbellMy DocumentsVS 2009ProjectsWindowsApplication1WindowsApplication1BinDebugSean.RPT


    Hope this helps,
    If you still cannot get it to work after entering the correct full-path of the file, please copy the details from the error message and paste them into your next reply,
    Sean Campbell
  • this is my complete code:
    [code]
    Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
    Try
    Dim cryRpt As New ReportDocument
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Billing").ConnectionString)

    Dim mmd As SqlCommand = conn.CreateCommand

    mmd.CommandType = CommandType.Text

    mmd.CommandText = "SELECT TOP 1 * FROM Bill ORDER BY [Current Date] DESC"

    conn.Open()
    Dim da As New SqlDataAdapter(mmd)
    Dim mytable As New DataTable("Billing")

    da.Fill(mytable)
    mmd.ExecuteNonQuery()

    cryRpt.SetDataSource(mytable)
    cryRpt.Load("C:Documents and Settingssaquib1My DocumentsVisual Studio 2008ProjectsMemorial SoftwareMemorial SoftwareMemorial.rpt")
    CrystalReportViewer1.ReportSource = cryRpt
    CrystalReportViewer1.Update()
    CrystalReportViewer1.Refresh()
    conn.Close()
    Catch ex As Exception
    MessageBox.Show("An Error has occured: " + ex.Message.ToString + vbCrLf)
    Finally

    End Try

    End Sub
    [/code]
    and i set the breakpoint in cryRpt.Load and it's display the error that Invalid file path but Nothing any wrong path included in it. and also when i commented the line "cryRpt.SetDataSource(mytable)" it display the report but with no database binding and nothing display on the report. Can i send u my DB with report and form files.
  • seancampbellseancampbell Pennsylvania, USA
    I need you to paste the FULL details of the error message it gives you.

    Remove the Try Catch, let the program crash, click Details>>, copy the contents of the details and paste it into a reply.
  • [img=http://4.bp.blogspot.com/_i14Hz19WAp8/SykjWAB8s4I/AAAAAAAAAcY/DxZ7V15S8zo/s1600-h/error1.jpg] if the image not display paste the image link to address bar:
    http://4.bp.blogspot.com/_i14Hz19WAp8/SykjWAB8s4I/AAAAAAAAAcY/DxZ7V15S8zo/s1600-h/error1.jpg

    and the error details:

    CrystalDecisions.CrystalReports.Engine.LoadSaveReportException was unhandled
    Message="Invalid report file path."
    Source="CrystalDecisions.Shared"
    StackTrace:
    at CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String messageID, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type) at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataTable dataTable) at WindowsApplication1.CrystalRep.RadButton1_Click(Object sender, EventArgs e) in C:Documents and Settingssaquib1My DocumentsVisual Studio 2008ProjectsMemorial SoftwareMemorial SoftwareCrystalRep.vb:line 33 at System.Windows.Forms.Control.OnClick(EventArgs e) at Telerik.WinControls.RadControl.OnClick(EventArgs e) at Telerik.WinControls.UI.RadButton.ButtonElement_Click(Object sender, EventArgs e) at Telerik.WinControls.RadItem.OnClick(EventArgs e) at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e) at Telerik.WinControls.RadItem.DoClick(EventArgs e) at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args) at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args) at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args) at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args) at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e) at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e) at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at Telerik.WinControls.RadControl.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

  • seancampbellseancampbell Pennsylvania, USA
    Mind you, I really don't have any experience with this, but here is what I think is going on...

    You have to Load the Report before you set the data source... so swap your .Load and .SetDataSource lines of code to look like this:

    [code]
    cryRpt.Load("C:Documents and Settingssaquib1My DocumentsVisual Studio 2008ProjectsMemorial SoftwareMemorial SoftwareMemorial.rpt")
    cryRpt.SetDataSource(mytable)
    [/code]

    I came to this conclusion after finding some sample code. I assume that the program trys to load the rpt when you set the DataSource (to fill it out with the data it was provided) then it throws a LoadException because the FileName is blank or nothing.

    Try this and let me know if it resolves it, if not we can look at other things. Here is that sample code i found, its a tutorial:
    http://www.thescarms.com/dotnet/CrystalRptViewer.aspx
  • Thank u thank u sir, it works. why its not came in my mind. if i get any problem i will contact u.

    thanks you
  • I have a similiar problem.
    I made crystal reports and they run in VS2008 localhost and then I deploy to my client for windows application.
    The invalid report path error exists at report view.
    I had already copied the crystal reports *.rpt to client's c:MyReport folder-same as VS2008 environment and stil same error.

    Any solution?

    Tommy Leung.
  • seancampbellseancampbell Pennsylvania, USA
    Tommy, in order for us to help, you must post your exact code that is crashing, and the details from the Exception that is thrown.
  • Thanks.
    I found out I need to further config project setup for crystal report under VS2008, I am following the link in :

    http://msdn.microsoft.com/en-us/library/bb126227(VS.90).aspx

    Will report my result.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories