Want to see what people are talking about? See the latest forum posts.

VB.NET

Moderators: seancampbell
Number of threads: 3679
Number of posts: 9418

This Forum Only
Post New Thread

Report
Crystal Report Posted by saquib189 on 13 Dec 2009 at 4:40 AM
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.
Report
Re: Crystal Report Posted by seancampbell on 13 Dec 2009 at 2:57 PM
Please paste your source code in a "code" block.
Report
Re: Crystal Report Posted by saquib189 on 13 Dec 2009 at 10:14 PM
my code is as here under:
 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


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
Report
Re: Crystal Report Posted by seancampbell on 14 Dec 2009 at 6:46 AM
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

Dim dtNow as Date = Now
MessageBox.Show(dtNow)


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
Report
Re: Crystal Report Posted by saquib189 on 14 Dec 2009 at 1:15 PM
Hi Thanx for ur reply, Now i added Crystal Report 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


but the following error occurs: Invalid Report File Path
Report
Re: Crystal Report Posted by seancampbell on 15 Dec 2009 at 6:25 AM
Dim str As String = "Report Directory/bill.RPT"


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:

Dim str as String = "C:\Program Files\Some Folder I Just Made\SeanCampbell.RPT"


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:

Dim Str as String = "Sean.RPT"

When I go to load this file, it will look in this path:
C:\Documents and Settings\SeanCampbell\My Documents\VS 2009\Projects\WindowsApplication1\WindowsApplication1\Bin\Debug\Sean.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
Report
Re: Crystal Report Posted by saquib189 on 15 Dec 2009 at 11:53 AM
this is my complete 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 Settings\saquib1\My Documents\Visual Studio 2008\Projects\Memorial Software\Memorial Software\Memorial.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

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.
Report
Re: Crystal Report Posted by seancampbell on 15 Dec 2009 at 12:09 PM
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.
Report
Re: Crystal Report Posted by saquib189 on 16 Dec 2009 at 11:17 AM
Report
Re: Crystal Report Posted by saquib189 on 16 Dec 2009 at 11:22 AM
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 Settings\saquib1\My Documents\Visual Studio 2008\Projects\Memorial Software\Memorial Software\CrystalRep.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:

Report
Re: Crystal Report Posted by seancampbell on 17 Dec 2009 at 6:45 AM
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:

cryRpt.Load("C:\Documents and Settings\saquib1\My Documents\Visual Studio 2008\Projects\Memorial Software\Memorial Software\Memorial.rpt")
cryRpt.SetDataSource(mytable)


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
Report
Re: Crystal Report Posted by saquib189 on 17 Dec 2009 at 9:46 AM
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



 
Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2010 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
bootstrapLabs Logo A BootstrapLabs project.