-
Nov 12th, 2006, 03:26 AM
#1
Thread Starter
Just Married
Crystal Report In VB.NET
Often user get problem for making the report using Vb.Net so here I am providing the simple code for using the report in the VB.NET
This code simply on the Form Load event, you can change it according to the button also. You have to add just connection and the query according to your project.
If you do not want to use the SQL query then you can use the selection formulas also
If any problem related to this code then post me in The PM do not post here Contact me at the PM or post in the reporting section I will check your problem there.
Step By Step Crystal Report In VB.NET New Code
1) Add a from in your project Name CrystalReportForm
2) Add a panel Set the Dock Property To Fill
3) Add the Code
VB.NET Code:
Imports System.Data.OleDb
Public Class CrystalReportForm
Public Function GetDataAdeptor(ByVal QueryString As String) As OleDbDataAdapter
Dim DataAdapter As New OleDbDataAdapter
Try
Dim NewConnection As OleDbConnection = OpenNewConnection()
DataAdapter = New OleDbDataAdapter(QueryString, NewConnection)
Return DataAdapter
Catch ex1 As OleDbException
Throw New Exception("Error Getting The Table", ex1)
Catch ex As Exception
Throw New Exception("Error Getting The DataAdapter", ex)
End Try
End Function
''' <summary>
''' Open Connection Here
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function OpenNewConnection() As OleDbConnection
Dim NewConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=StartUpPath\Database.mdb;Jet OLEDB:Database Password='ShaktiSinghDulawat';")
Try
NewConnection.Open()
Return NewConnection
Catch ex As Exception
Throw (ex)
End Try
End Function
''' <summary>
''' 1)Add Windows Form Name CrystalReportForm
''' 2)Add A Panel Set Dock Proprty To Fill
''' </summary>
''' <param name="ReportName">Report Name Contain The Name</param>
''' <param name="TableName">Table Name In Array</param>
''' <param name="QueryString">Query String In Array</param>
''' <param name="Parameter">Parameter If Any</param>
''' <remarks></remarks>
'''
Friend Sub ViewReport(ByVal ReportName As String, ByVal TableName() As String, ByVal QueryString() As String, Optional ByVal [Parameter] As String = "")
Me.MdiParent = MainForm
If Not UBound(TableName).Equals(UBound(QueryString)) Then MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub
Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
CrystalReportViewer.ActiveViewIndex = 0
CrystalReportViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
CrystalReportViewer.DisplayGroupTree = False
CrystalReportViewer.Dock = System.Windows.Forms.DockStyle.Fill
CrystalReportViewer.Location = New System.Drawing.Point(0, 0)
CrystalReportViewer.Name = "CrystalReportViewer"
Dim Adapter As New OleDb.OleDbDataAdapter
Dim DataSet As New DataSet
For I As Integer = 0 To UBound(TableName)
Adapter = GetDataAdeptor(QueryString(I))
Adapter.Fill(DataSet, TableName(I))
Next
'Report In the report Folder
Report.Load(Application.StartupPath & "/Report/" & ReportName & "")
Report.SetDataSource(DataSet)
If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
CrystalReportViewer.ReportSource = Report
Me.Panel1.Controls.Add(CrystalReportViewer)
End Sub
End Class
How to Call It
1) Make a Crystal Report and save it in the Report folder at the application startup Path, Just add the Name of the report as CrystalReport1
2) Make a new form add a command button
Call This Function for single Table
VB.NET Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ReportForm As New CrystalReportForm
Dim TableName(0) As String
Dim QueryString(0) As String
TableName(0) = "TableName" 'Pass The Table That you used in the crystal Report
QueryString(0) = "SELECT * FROM TableName" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
ReportForm.ViewReport("CrystalReport1.rpt", TableName, QueryString, )
' You can pass the Parameter Value It is Optional
ReportForm.Show()
End Sub
For Multiple table Increase the array
VB.NET Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ReportForm As New CrystalReportForm
Dim TableName(1) As String
Dim QueryString(1) As String
TableName(0) = "Table1"
TableName(1) = "Table2"
QueryString(0) = "SELECT * FROM Table1"
QueryString(1) = "SELECT * FROM Table2"
ReportForm.MdiParent = MainForm
'Here I am Passing the value of Parameter
ReportForm.ViewReport("CrystalReport1.rpt", TableName, QueryString, "UnRegister")
ReportForm.Show()
End Sub
Still I am Making some modification In the Code as it work successfully I will Tell.
EDIT :14 June 2007
Add the following reference in your project.
VB.NET Code:
CrystalDecisions.CrystalReport.Engine
CrystalDecisions.Enterprise.Framework
CrystalDecisions.Enterprise.infoStore
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.Web
CrystalDecisions.Windows.Forms
Code For The MS Access And The SQL Server 2005 Thanks
Thanks
Last edited by shakti5385; Jun 25th, 2007 at 08:02 AM.
Reason: Add Reference list On 14 June 2007 For running Crystal Report
-
Nov 17th, 2006, 09:26 AM
#2
New Member
Re: Crystal Report In VB.NET
Hello,
your example is very good.
So now i have a question: how do to get the sql query that is in my report in vb.net?
Sorry for my bad english
billy21
-
Nov 18th, 2006, 11:11 AM
#3
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Just check the following code this is your solution.
Here both that table1 and the table2 are in the crystal report and passing the query here.rpt.SetDataSource(ds)
Above code filling the data source from the related table.
VB Code:
Dim connection As New OleDbConnection(funcs.con)'Open New Connection Here
connection.Open()
Dim QueryString As String
QueryString = "Select * from Table1 Where ID=" & TextBox1.Text & ""
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(QueryString, connection)
Dim ds As DataSet = New DataSet()
Adapter.Fill(ds, "Table1")
QueryString = "Select * from Table2" ' Where ID=" & TextBox1.Text & ""
Adapter = New OleDbDataAdapter(QueryString, connection)
ds = DataSet()
Adapter.Fill(ds, "Table2")
rpt.Load(Application.StartupPath & "/ReportName.rpt")
rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rpt
Last edited by shakti5385; Dec 7th, 2006 at 04:35 AM.
-
Dec 10th, 2006, 12:35 AM
#4
Hyperactive Member
Re: Crystal Report In VB.NET
Can u send the Sample Code for this ? I really want it.
I am using .NET 2010 with Windows 7
-
Feb 8th, 2007, 01:35 PM
#5
New Member
Re: Crystal Report In VB.NET
Dear Shakti5385,
I'm Impressed with what u have posted but unfortunantly still it doesnt solve my problem, so i thought i'll drop this message that you might be able to help me. So i'll tell you what i am using, i am using VS.NET 2003, MySQL and MySQL Server and I'm using ODBC connection to connect VB.NET and MySQL so the problem with this connection is i cant create datasets with it etc.. here is how i connect:
Public MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=*****;" & _
"UID=*****;" & _
"PASSWORD=****;" & _
"OPTION=3;"
and sql querries like this:
Dim MyCommand As New Odbc.OdbcCommand
Dim fdCom4 As New Odbc.OdbcCommand("SELECT * FROM order ", MyConnection) and
MyCommand.CommandText = "INSERT INTO blabla SELECT * FROM order " ' when creating network need to add which user name is logged
MyCommand.Connection = MyConnection
Please can you help me on how to view crystal report, the code you have published i have tried to amend it but still cant make it work
Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
CrystalReportViewer1.ActiveViewIndex = 0
' CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
CrystalReportViewer1.DisplayGroupTree = False
CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
CrystalReportViewer1.Name = "CrystalReportViewer1"
Dim MyConnection As New Odbc.OdbcConnection(MyConString)
Dim MyCommand As New Odbc.OdbcCommand
Dim fdCom4 As New Odbc.OdbcCommand("SELECT * FROM t_order ", MyConnection)
'Dim QueryString As String = "select * from TableName" 'Your Query here
'Dim Connection As New OleDbConnection(funcs.con) 'Your Database Connection Here
MyConnection.Open()
Dim Adapter As Odbc.OdbcDataAdapter ' = New Odbc.OdbcDataAdapter(fdCom4, MyConnection) 'Passing the query in the connection
' Dim DataSet As DataSet = New DataSet 'DataSet
' Adapter.Fill(DataSet)
Dim DataTable As DataTable = New DataTable 'DataTable
'DataTable = DataSet.Tables(0) 'filling the datatable here
Report.Load("../CrystalReport1.rpt") 'Report Name Here
Report.SetDataSource(DataTable)
CrystalReportViewer1.ReportSource = Report
Please help me,
regards
Tosi
-
Apr 4th, 2007, 04:02 PM
#6
Junior Member
Re: Crystal Report In VB.NET
Everything is working beautifully but what if I want my reports to be within my project? How do I set it to find it?
For Example the following code I know Loads the report form from a folder but I want it to use a resource in my code:
Code:
'Report In the report Folder
Report.Load(Application.StartupPath & "/Report/" & ReportName & "")
-
Apr 4th, 2007, 05:41 PM
#7
New Member
Re: Crystal Report In VB.NET
hi there!!
Do u mean to load to a VB.Net form? if so u need CrystalReport Viewer where u can get on the tool menu.
regards
tosi
-
Apr 4th, 2007, 06:24 PM
#8
Junior Member
Re: Crystal Report In VB.NET
No I have the Viewer but I want to set the report it views programmatically without storing the .rpt in a subfolder.
-
Apr 5th, 2007, 08:07 AM
#9
New Member
Re: Crystal Report In VB.NET
i very much doubt you can do that......................
-
Apr 5th, 2007, 04:10 PM
#10
Junior Member
Re: Crystal Report In VB.NET
Originally Posted by tosi007
i very much doubt you can do that......................
hmm see I can add a report to my project but it binds it to a database upon creation the Crystalreport.rpt is in the list of files within my project. Why can't I just programmatically bind the form to the viewer but be able to set the location of the database eachtime it's called?
You can do this witht the Folder method I just wanted to leave my forms internal to the program structure and not external in a folder to be called.
But if I have to, the folder method works just fine.
-
Apr 5th, 2007, 06:34 PM
#11
New Member
Re: Crystal Report In VB.NET
hmm well i have to say that will be a challange for me as well, but anyhow i will post here the way i conneted to database (odbc) and i hope it helps.
p.s. if you cant connect two tables together you need to do this right click database --> verify database it took me ages to find out and i even lost some hair lol
I am using mySQL, ODBC driver and VS.NET 2003 which came with Crystal Report.
vb Code:
Public MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=******;" & _
"UID=*****;" & _
"PASSWORD=*****;" & _
"OPTION=3;"
Dim myReport As New ReportDocument
Dim myData As New DataSet
Dim myAdapter As New Odbc.OdbcDataAdapter
Dim MyConnection As New Odbc.OdbcConnection(MyConString)
Dim MyCommand As New Odbc.OdbcCommand
Dim invoice As String
Dim username As String
Dim txttotal As String
invoice = txtinvoice.Text
Try
'MyConnection.Open()
MyConnection.Open()
'select all from o_mhiring and o_customer table to create an invoice
MyCommand.CommandText = "SELECT m.mh_name, m.start_date, m.end_date, m.price, m.username, m.invoice_no, m.date, m.total_days, m.g_total, o.c_name, o.c_surname, o.c_add1, o.c_add2, o.c_add3, o.c_pc, o.c_passport, o.c_dlicence, o.c_phone, o.c_email, o.c_invoice_no FROM o_mhiring m INNER JOIN o_customer o WHERE m.invoice_no = '" & invoice & "' AND m.invoice_no = o.c_invoice_no "
MyCommand.Connection = MyConnection
myAdapter.SelectCommand = MyCommand
myAdapter.Fill(myData) 'fill data and load report
myReport.Load("..\Printmhirings.rpt")
myReport.Database.Tables(0).SetDataSource(myData.Tables(0))
MyViewer.ReportSource = myReport
Catch ex As Exception
MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'close connection
MyConnection.Close()
-
Apr 7th, 2007, 01:51 AM
#12
New Member
Re: Crystal Report In VB.NET
i want help abt report in vb2005
-
Apr 7th, 2007, 04:51 AM
#13
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Originally Posted by kripa ostwal
i want help abt report in vb2005
Read the article carefully.
-
Apr 7th, 2007, 05:23 AM
#14
Junior Member
Re: Crystal Report In VB.NET
Originally Posted by Troy Davis
hmm see I can add a report to my project but it binds it to a database upon creation the Crystalreport.rpt is in the list of files within my project. Why can't I just programmatically bind the form to the viewer but be able to set the location of the database eachtime it's called?
You can do this witht the Folder method I just wanted to leave my forms internal to the program structure and not external in a folder to be called.
But if I have to, the folder method works just fine.
As you can see by the areas I have circled, I can create new Crystal reports very easily with the tools to the left. And They are added to my list of Project files to the right.
But doing it that way binds the report to a fixed database location.
I can export and save the report then put it into a folder and load it using code just fine then that allows me to provide a different Database location.
I was hoping there was a way I could use code to provide the viewer with the Report name in my project and also the database location like in the Report.Load statement.
If you can setup a methode to call a form like frmMain.show() or use a class form or Modules why can't you find a way to bind the reports.
Last edited by Troy Davis; Apr 7th, 2007 at 04:09 PM.
-
May 2nd, 2007, 10:34 PM
#15
Hyperactive Member
Re: Crystal Report In VB.NET
Originally Posted by kripa ostwal
i want help abt report in vb2005
I am facing the same problem too!
The example on the above that is very good.
But that cannot be apply in vb 2005, I think that code is for vb 2003
-
May 2nd, 2007, 11:33 PM
#16
Junior Member
Re: Crystal Report In VB.NET
Originally Posted by newpat
I am facing the same problem too!
The example on the above that is very good.
But that cannot be apply in vb 2005, I think that code is for vb 2003
I use VB 2005 and the above code works just fine.
-
May 3rd, 2007, 01:03 AM
#17
Thread Starter
Just Married
Re: Crystal Report In VB.NET
I just edit My First Post
-
May 3rd, 2007, 11:47 AM
#18
Hyperactive Member
Re: Crystal Report In VB.NET
I see u use oledb, but I am using odbc, so I think there is the main different
-
May 4th, 2007, 12:04 PM
#19
Re: Crystal Report In VB.NET
If you are trying to access a report that is a file in your project you can just create an instance of it and then apply tablelogon info like so
vb.net Code:
Dim Report As New MyReport1
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
ConInfo.ConnectionInfo.UserID = "YORTU_USER"
ConInfo.ConnectionInfo.Password = "YOUR_PASS"
ConInfo.ConnectionInfo.DatabaseName = "YOUR_DATABASE"
For intCounter As Integer = 0 To Report.Database.Tables.Count - 1
Report.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next
-
May 4th, 2007, 02:19 PM
#20
Hyperactive Member
Re: Crystal Report In VB.NET
ha, why I use this code and so exception?(extract some from my code
Code:
Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = New FormC Form is my name of report form.
Dim DataSet As New Data.DataSet()
rpt.SetDataSource(DataSet)
exception:
DataSourceException
-
May 16th, 2007, 10:39 AM
#21
New Member
Re: Crystal Report In VB.NET
Hello
Thank you shakti5385 for the code, I found it most helpful.
But I was wondering if I can use the same code for creating a Crystal Report From an XML file, or is it done through a different method?
Thank you again
Best Regards,
Joody
-
May 28th, 2007, 01:18 AM
#22
Junior Member
Re: Crystal Report In VB.NET
hello am using the following code
Friend Sub ViewReport(ByVal ReportName As String, ByVal TableName() As String, ByVal QueryString() As String, Optional ByVal [Parameter] As String = "")
Dim l_objDBManager As DBManager.DBManager
Me.MdiParent = frmMain
If Not UBound(TableName).Equals(UBound(QueryString)) Then
MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub
End If
Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
CrystalReportViewer.ActiveViewIndex = 0
CrystalReportViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
CrystalReportViewer.DisplayGroupTree = False
CrystalReportViewer.Dock = System.Windows.Forms.DockStyle.Fill
CrystalReportViewer.Location = New System.Drawing.Point(0, 0)
CrystalReportViewer.Name = "CrystalReportViewer"
Dim Adapter As System.Data.SqlClient.SqlDataAdapter
l_objDBManager = New DBManager.DBManager
Dim DataSet As New DataSet
l_objDBManager.SetConn()
For I As Integer = 0 To UBound(TableName)
Adapter = l_objDBManager.GetDataAdeptor(QueryString(I))
Adapter.Fill(DataSet, TableName(I))
Next
Report.Load(Application.StartupPath & "/Reports/" & ReportName & "")
Report.SetDataSource(DataSet)
'Report.Database.Tables(0).SetDataSource(DataSet.Tables(0))
If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
CrystalReportViewer.ReportSource = Report
Me.Panel1.Controls.Add(CrystalReportViewer)
l_objDBManager.DisposeConn()
End Sub
but it gives exception on the line Report.SetDataSource(DataSet) that report has no table ....can ny1 help me
-
May 29th, 2007, 03:08 AM
#23
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Be sure that all the table you are using in the crystal report are passed in the table array in my function.
-
May 29th, 2007, 11:07 AM
#24
Junior Member
Re: Crystal Report In VB.NET
Ok, this may sound stupid, but I'm still new to VB2005. How do I create a Crystal Report in Report dir?
I've tried creating the file and moving it, but that doesn't work.
Thanks,
Tony
-
Jun 11th, 2007, 07:11 AM
#25
Junior Member
Re: Crystal Report In VB.NET
OK, disregard my last post, it was a stupid question.
Now I have an error I cant figure out.
Code:
Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
Can someone please help?
Thanks,
Tony
-
Jun 11th, 2007, 07:18 AM
#26
Junior Member
Re: Crystal Report In VB.NET
Originally Posted by akernan
OK, disregard my last post, it was a stupid question.
Now I have an error I cant figure out.
Code:
Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
Can someone please help?
Thanks,
Tony
Make sure you added this
Code:
Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Correctly. If it's not spelled correctly it will dim the wrong variable.
Can't really tell for sure unless we see your code.
-
Jun 11th, 2007, 10:40 AM
#27
Junior Member
Re: Crystal Report In VB.NET
I copied the code directly from the first post.
-
Jun 12th, 2007, 01:02 AM
#28
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Originally Posted by akernan
I copied the code directly from the first post.
Just add the reference of crystal report in your project. Project >Click>Add Reference
Then this will work.
-
Jun 12th, 2007, 05:14 PM
#29
Junior Member
Re: Crystal Report In VB.NET
Imanaged to get something to work. Thnks for the replies.
-
Jun 14th, 2007, 12:34 AM
#30
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Add the following reference in your project.
CrystalDecisions.CrystalReport.Engine
CrystalDecisions.Enterprise.Framework
CrystalDecisions.Enterprise.infoStore
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.Web
CrystalDecisions.Windows.Forms
-
Jul 9th, 2007, 06:52 AM
#31
Addicted Member
Re: Crystal Report In VB.NET
the above code works for crystal reporst. wat if i need to put the database contents in crystal reports viewer? how can i do that?
-
Jul 9th, 2007, 07:20 AM
#32
Thread Starter
Just Married
Re: Crystal Report In VB.NET
I am also using crystal reports viewer check it carefully!!
-
Jul 25th, 2007, 02:54 AM
#33
Hyperactive Member
Re: Crystal Report In VB.NET
Hi shakti,
I am passing the following code in order to automatically logon the database server:
vb Code:
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
ConInfo.ConnectionInfo.UserID = "SCOTT"
ConInfo.ConnectionInfo.Password = "tiger"
ConInfo.ConnectionInfo.DatabaseName = "sun"
Report.Database.Tables(0).ApplyLogOnInfo(ConInfo)
But it's giving me the following error:
Invalid report file path.
I am using adodb connection and i have added all the references.
-
Aug 2nd, 2007, 08:34 AM
#34
Thread Starter
Just Married
Re: Crystal Report In VB.NET
Please put all the report in a Report folder and set this folder at the application startup path!
-
Nov 14th, 2008, 01:20 PM
#35
New Member
Re: Crystal Report In VB.NET
Hi this is really informative man!!!!!!!!!!
I was impressed!!!!!!!!
-
Jan 11th, 2009, 02:55 PM
#36
New Member
Re: Crystal Report In VB.NET
Excellent sample program!
I am trying to write an application which displays previously created Crystal Reports for our employees. They have requested the ability to display the SQL query sent to the database. I know this can be viewed when using Crystal itself but we would rather have a way to display it as part of our application. Also, many of our reports are based on a command rather than created through the wizard's table links.
Any help would be appreciated!
-
Feb 13th, 2009, 11:25 AM
#37
Thread Starter
Just Married
Re: Crystal Report In VB.NET
-
Sep 25th, 2009, 08:48 AM
#38
New Member
Re: Crystal Report In VB.NET
You cannot view the SQL Query being passed to the database in a windows application. You can however view the SQL Query if you create a web based application.
-
Oct 30th, 2009, 02:06 AM
#39
New Member
Re: Crystal Report In VB.NET
Here Experts here is my codings......
Dim ds As New DataSet
ds = New DataSet("LKG")
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Working\Sri\My project works\VVB\Vinayaga Vidhya Bhavan\Vinayaga Vidhya Bhavan\bin\Debug\vvb.mdb"
Dim Connection1 As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConnectionString)
Dim Command1 As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM LKG")
Connection1.Open()
Command1.Connection = Connection1
Dim OleDbDataAdapter1 As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
OleDbDataAdapter1.SelectCommand = Command1
OleDbDataAdapter1.TableMappings.Add("table", "LKG")
OleDbDataAdapter1.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)----> no error
CrystalReport11.SetDataSource(ds.Tables(0))---> no tables in report
Public Class Form1
Public ds As New DataSet1
Public Sub rep()
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Working\Sri\My project works\VVB\Vinayaga Vidhya Bhavan\Vinayaga Vidhya Bhavan\bin\Debug\vvb.mdb")
cn.Open()
Dim da As New OleDb.OleDbDataAdapter("select * from LKG", cn)
da.Fill(ds, "LKG")
End Sub
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
Call rep()
Dim obj As New CrystalReport1
obj.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ReportSource = obj
End Sub
Some one help me please
what should i do? very urgent!
-
Mar 4th, 2010, 02:58 AM
#40
Frenzied Member
Re: Crystal Report In VB.NET
Hi:
Sorry to open the post but i want to try your code and i have this message in this line:
"Type CrystalReportForm it's not defined"
I had follow all the steps that you tell in your post...something wrong?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ReportForm As New CrystalReportForm
Dim TableName(0) As String
Dim QueryString(0) As String
TableName(0) = "Lancamentos" 'Pass The Table That you used in the crystal Report
QueryString(0) = "SELECT * FROM TableName" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
ReportForm.ViewReport("MapaRecapitulativo.rpt", TableName, QueryString, )
' You can pass the Parameter Value It is Optional
ReportForm.Show()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|