[RESOLVED] creating crystal report from dataset
Hi
I want to create a crystal report from the dataset that i have written code for. All the information on google i found is the crystal report using database. I am not using any database. I have created table as below
Code:
Public Class Form1
Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'creating a table named Customers
Dim Row1, Row2, Row3 As DataRow
'declaring three rows for the table
Dim FirstName As DataColumn = New DataColumn("FirstName")
'declaring a column named Name
FirstName.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
Table1.Columns.Add(FirstName)
'adding the column to table
Dim LastName As DataColumn = New DataColumn("LastName")
LastName.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(LastName)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("FirstName") = fname.Text.ToString
'filling the row with values. Item property is used to set the field value.
Row1.Item("LastName") = "Notebook"
Table1.Rows.Add(Row1)
Dim ds As New DataSet()
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
'filling the row with values. adding a product
pfname.Text = Table1.Rows(0).Item("FirstName")
End Sub
End Class
Now i want to generate a crystal report from the dataset (ds) that i have created.
Re: creating crystal report from dataset
Re: creating crystal report from dataset
hey my friend
read this one i think it is what you are looking for:-
Crystal Report
Re: creating crystal report from dataset
Quote:
Originally Posted by
snakeman
hey my friend
read this one i think it is what you are looking for:-
Crystal Report
You r right Snakeman...i think i need that one...i will try when i go home....and will let u know....thanks Mate....
Re: creating crystal report from dataset
Quote:
Originally Posted by
snakeman
hey my friend
read this one i think it is what you are looking for:-
Crystal Report
i followed as much as i could but the tutorial is missing few steps and i get stuck what to do then.....like it says
Quote:
For adding crystal reports to our application, right click the project and select add-> add new item menu. The following dialog box will come. We can select the crystal report from the stated dialog.
The Crystal report is a file with .rpt extension. While adding the report, the developing environment automatically binds it with a class file with the same name of the report. The class file contains the resource name i.e. the .rpt file, all the sections inside the .rpt file and some other information. This .cs file is used for the interface between the report and the application.
but when u follow on VS2005 there are more steps then showed in the tutorial and i dont know what to select in that.
The other confusion is ...when i go to the following step
Quote:
Open the xsd file and from the toolbox, click element object and drag to the work area. This operation will add a table to the dataset. We can design the table according to our requirements and it provides almost all the data types for a table design. We can add any number of tables into one dataset.
I could not fine "element object" i think i am missing steps which is not shown in the tutorial.....
can u pls help with that
Re: creating crystal report from dataset
Quote:
Originally Posted by
snakeman
hey my friend
read this one i think it is what you are looking for:-
Crystal Report
Hi
I fond another tutorial and followed it successfully but gives me an error mes
Code:
System.IndexOutOfRangeException was unhandled
Message="Cannot find table 1."
Source="System.Data"
StackTrace:
at System.Data.DataTableCollection.get_Item(Int32 index)
at crystalrep1.Form1.Print_Click(Object sender, EventArgs e) in C:\Users\aaisha\Documents\Visual Studio 2005\Projects\crystalrep1\crystalrep1\Form1.vb:line 48
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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 crystalrep1.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()
My code is as below
Code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Public Class Form1
Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'creating a table named Customers
Dim Row1, Row2, Row3 As DataRow
'declaring three rows for the table
Dim FirstName As DataColumn = New DataColumn("FirstName")
'declaring a column named Name
FirstName.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
Table1.Columns.Add(FirstName)
'adding the column to table
Dim LastName As DataColumn = New DataColumn("LastName")
LastName.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(LastName)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("FirstName") = fname.Text.ToString
'filling the row with values. Item property is used to set the field value.
Row1.Item("LastName") = "Notebook"
Table1.Rows.Add(Row1)
Dim ds As New DataSet()
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
'filling the row with values. adding a product
pfname.Text = Table1.Rows(0).Item("FirstName")
Dim objRpt As New CrystalReport1
objRpt.SetDataSource(ds.Tables(1))
CrystalReportViewer1.ReportSource = objRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
i have highlighted the line where the error is
Re: creating crystal report from dataset
try:
objRpt.SetDataSource(ds.Tables(0))
Re: creating crystal report from dataset
Quote:
Originally Posted by
.paul.
try:
objRpt.SetDataSource(ds.Tables(0))
thanks mate that worked
Re: [RESOLVED] creating crystal report from dataset
I needed to the same thing. When I tried your final code I get an error message " The report has no tables" with on the line
objRpt.SetDataSource(ds.Tables(0))
I get the same error with "ds.Tables(1))"
Can anyone shed any light please
I am using VB in Visual Studio 2008
Thanks
Re: [RESOLVED] creating crystal report from dataset
Quote:
Originally Posted by
Paulnz
I needed to the same thing. When I tried your final code I get an error message " The report has no tables" with on the line
objRpt.SetDataSource(ds.Tables(0))
I get the same error with "ds.Tables(1))"
Can anyone shed any light please
I am using VB in Visual Studio 2008
Thanks
can you post your code?
Re: [RESOLVED] creating crystal report from dataset
HI Paul
Code is as follows and error is on line
objRpt.SetDataSource(ds.Tables(0))
by the way I do not know what "fname" and "pfname" are and have created text boxes for them.
Thanks
Imports System.Data
Public Class Form1
Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'creating a table named Customers
Dim Row1, Row2, Row3 As DataRow
'declaring three rows for the table
Dim FirstName As DataColumn = New DataColumn("FirstName")
'declaring a column named Name
FirstName.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
Table1.Columns.Add(FirstName)
'adding the column to table
Dim LastName As DataColumn = New DataColumn("LastName")
LastName.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(LastName)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("FirstName") = fname.Text.ToString
'filling the row with values. Item property is used to set the field value.
Row1.Item("LastName") = "Notebook"
Table1.Rows.Add(Row1)
Dim ds As New DataSet()
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
'filling the row with values. adding a product
pfname.Text = Table1.Rows(0).Item("FirstName")
Dim objRpt As New CrystalReport1
objRpt.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ReportSource = objRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
1 Attachment(s)
Re: [RESOLVED] creating crystal report from dataset
heres an example. you'll find you need to add a new dataset to your project, and use it as the datasource for your crystalreport, then at runtime you need to create + populate an identical dataset which you then set as your datasource in code.
Re: [RESOLVED] creating crystal report from dataset
HI Paul.
Thank you
Paulnz