# VBForums CodeBank > CodeBank - Visual Basic .NET >  Crystal Report In VB.NET

## shakti5385

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  :Thumb: 
Thanks  :Thumb:

----------


## billy21

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

----------


## shakti5385

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.  :wave:  




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

----------


## Coool

Can u send the Sample Code for this ? I really want it.

----------


## tosi007

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

----------


## Troy Davis

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:



```
'Report In the report Folder    
Report.Load(Application.StartupPath & "/Report/" & ReportName & "")
```

----------


## tosi007

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

----------


## Troy Davis

No I have the Viewer but I want to set the report it views programmatically without storing the .rpt in a subfolder.

----------


## tosi007

i very much doubt you can do that......................

----------


## Troy Davis

> 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.

----------


## tosi007

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  :Wink:  it took me ages to find out and i even lost some hair lol  :Wink: 

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()

----------


## kripa ostwal

i want help abt report in vb2005

----------


## shakti5385

> i want help abt report in vb2005


Read the article carefully.

----------


## 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.

----------


## newpat

> 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 :wave:

----------


## Troy Davis

> 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. :Wink:

----------


## shakti5385

I just edit My First Post

----------


## newpat

I see u use oledb, but I am using odbc, so I think there is the main different :Frown:

----------


## bmahler

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

----------


## newpat

ha, why I use this code and so exception?(extract some from my 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

----------


## jooodyyy

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

----------


## sameen

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

----------


## shakti5385

Be sure that all the table you are using in the crystal report are passed in the table array in my function.

----------


## akernan

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

----------


## akernan

OK, disregard my last post, it was a stupid question.

Now I have an error I cant figure out.



```
Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
```

Can someone please help?

Thanks,
Tony

----------


## Troy Davis

> OK, disregard my last post, it was a stupid question.
> 
> Now I have an error I cant figure out.
> 
> 
> 
> ```
> Type 'CrystalDecisions.Windows.Forms.CrystalReportViewer' is not defined.
> ```
> ...


Make sure  you added this 



```
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.  :Wink:

----------


## akernan

I copied the code directly from  the first post.

----------


## shakti5385

> 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.  :Thumb:

----------


## akernan

Imanaged  to get something to work.  Thnks for the replies.

----------


## shakti5385

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

----------


## david_reinjal

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?

----------


## shakti5385

I am also using crystal reports viewer check it carefully!!

----------


## LuxCoder

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.

----------


## shakti5385

Please put all the report in a Report folder and set this folder at the application startup path!

----------


## ranu

Hi this is really informative man!!!!!!!!!!
I was impressed!!!!!!!!

----------


## John_24

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!

----------


## shakti5385

Thanks ranu and John

----------


## John_24

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.

----------


## SriramRamani

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!

----------


## sacramento

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

----------


## manuelpeh

i do all you say to do in the post, it does not give me an error but the crystalreport1 that opens is clear,  doesnt show nothing how i can correct that?

----------


## riendy

Report.Load("../CrystalReport1.rpt") 'Report Name Here
Report.SetDataSource(DataTable)
CrystalReportViewer1.ReportSource = Report

if i want to use more than one datasource, how to do that ?

----------


## dirs

Hi, I am using Visual Basic 6.0 and not VB.Net. Do you have code I can use to create Crystal report ( Crystal Report 2008) using VB6. I have searched many forums but still have not find code that works with VB 6.0 and Crystal Report 2008.
Thanks in advance

----------


## ADQUSIT

> 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
> ...


hi shakti bhaya, the report way you mentioned is using oledb connection, while i am working in sqlclient. so can you tell me that what i do now with this?

1 more thing is that, i want that when i end user call a report so it does not ask for username and password, means that automatically it picks up the username and password.

----------


## azad222

Hello

I read your article in the link
It was great
Now I have a question
This gives me an error

The report has no tables

This error is on the line below:

 Report.SetDataSource(DataSet)

In the following form.
CrystalReportForm.vb

Please help

Thanks

Mr Biroonvand

----------


## richardalgor

a simple sample code to connect vb.net to crystal reports using oledb

http://vb.net-informations.com/cryst...e_database.htm

there you can find lot of useful links .

algor

----------

