Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: invoice generation from database Post Reply Post New Topic
Author Message
podman99
Newbie
Newbie
Avatar

Joined: 06 Oct 2008
Location: United Kingdom
Online Status: Offline
Posts: 1
Quote podman99 Replybullet Topic: invoice generation from database
    Posted: 06 Oct 2008 at 3:27pm
I am new to VB.NET and Crystal reports however learning very quick, have a med size application to manage customers, however currently trying to generate invoice from my database

I have a database structure as follows (shortend for relevance)

client.id
client.name
client.company
client.email

invoice.id
invoice.clientid
invoice.vat
invoice.total

invoice_items.id
invoice_items.invoiceid
invoice_items.item
invoice_items.qty
invoice_items.unit

These table are related as follows

client.id <- one to many ->invoice.clientid
invoice.id <- one to many ->invocie_items.invoiceid

I have a need to create a report, which I have done however when I preview the report in VS2008 i see no data, thinking this was just a ONLY when running program issue I decided to build and run the application.

My code to load the report is


        Dim strReportName As String
        strReportName = "CrystalReport1"

        Dim strReportPath As String = "C:\" & _
       "\" & strReportName & ".rpt"

        If Not IO.File.Exists(strReportPath) Then
            Throw (New Exception("Unable to locate report file:" & _
              vbCrLf & strReportPath))
        End If

        Dim cr As New ReportDocument

        cr.Load(strReportPath)
        cr.SetDataSource(MassiveDataSet.Tables(0))

        Form1.CrystalReportViewer1.ShowRefreshButton = False
        Form1.CrystalReportViewer1.ShowCloseButton = False
        Form1.CrystalReportViewer1.ShowGroupTreeButton = False

        Form1.CrystalReportViewer1.ReportSource = cr
        Form1.Show()



What I think i need to do is sent the invoice.id to the report so that it can run the SQL query to display the report correctly.

Any help would be very welcomed, espicially good websites / posts with either tutorials or code for similar projects which I would need to read and learn.

Im sure what I'm doing requires me specifing somewhere in the report a query which chooses what invoice.id a report is being generated for, then obviously the above code would need to be updated to represent any changes required.

Thanks

Keith

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Oct 2008 at 2:42pm

Change this line:

cr.SetDataSource(MassiveDataSet.Tables(0))
 
to
 
cr.SetDataSource(MassiveDataSet)
 
-Dell
IP IP Logged
claudinei
Newbie
Newbie
Avatar

Joined: 03 Dec 2008
Location: Brazil
Online Status: Offline
Posts: 3
Quote claudinei Replybullet Posted: 03 Dec 2008 at 7:33pm
Group

   Good morning, I'm having a problem similar to the above, has not changed even more right, see the code below?
 

1) The opening screen of the database login, password to verify the claims that must be done?
2) And how should I do to refresh when the user presses, he update the report?

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm As New Form2
        frm.Show()
    End Sub
End Class
Public Class Form2
    Private Sub crptempresas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles crptempresas.Load
        Dim dbstrconexao As String = "User ID=system;Password=fernanda;Data Source=ORCL;"
        Dim dbcnnconexao As New OracleConnection
        Dim dbcmdconexao As New OracleCommand
        Dim dbdstconexao As New DataSet
        Dim telarpt As New relempresascrp
        dbcnnconexao.ConnectionString = dbstrconexao
        Try
            dbcnnconexao.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message, " Erro 1 ", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Try
            dbcmdconexao.Connection = dbcnnconexao
            With dbcmdconexao
                .CommandText = "BUSCAPORCEP"
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("CEP_ID", OracleType.NVarChar, 8).Value = Form1.TextBox1.Text.ToString
                .Parameters(0).Direction = ParameterDirection.Input
                .Parameters.Add("EMPRESAS_C", OracleType.Cursor)
                .Parameters(1).Direction = ParameterDirection.Output
            End With
            Try
                Dim dbadpconexao As New OracleDataAdapter(dbcmdconexao)
                dbadpconexao.Fill(dbdstconexao)
                telarpt.SetDataSource(dbdstconexao.Tables(0))
                crptempresas.ReportSource = telarpt
            Catch ex As Exception
                MessageBox.Show(ex.Message, " Erro 2 ", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        dbcmdconexao.Dispose()
        dbcnnconexao.Close()
        dbcnnconexao.Dispose()
    End Sub
End Class
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Dec 2008 at 7:28am

Is there a reason why you're using a dataset instead of connecting directly to the tables?

-Dell
IP IP Logged
claudinei
Newbie
Newbie
Avatar

Joined: 03 Dec 2008
Location: Brazil
Online Status: Offline
Posts: 3
Quote claudinei Replybullet Posted: 04 Dec 2008 at 11:08am
 
  What would be the other way, based on the code below?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Dec 2008 at 12:48pm
Connect the Crystal report to either a command or the tables in the database.  Your application would do the following:
 
- Create the report document object.
- Set the connection info for each of the tables in the report.
- Set the parameter info, if any, for the report.
- Set the ReportSource of the viewer to the report.
- View.
 
There is sample code for this in the Developer Library at http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/devsuite.htm.  Click on "Crystal Reports .NET SDK", then on ".NET Developer Guide and Reference", then on "Tutorials and Sample Code".  There is sample VB.NET code available.
 
-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.