Solved

How to Create a Crystal Reports from sql query string in vb.net

Posted on 2009-05-14
7
1,014 Views
Last Modified: 2012-05-07
I tried to create a crystal report according to the user choice in a vb form. For that i like to pass a dynamically generated query
to crystal report. But when im assigning the "SetDataSource" property of CR by the following coding its giving the error
 
"Object reference not set to an instance of an object ." ....

i used the following coding...




help me...

Thanks in advance
Public Class Form1

    Dim rpt As CrystalReport1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim cnn As OleDbConnection

 

     

        cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ELA\Current\Tailor_Software\TailorDb.mdb")

        cnn.Open()

       

        Dim da As New OleDbDataAdapter("select * from User_Master", cnn)

        Dim ds As New DataSet

        da.Fill(ds, "User_Master")

 

         rpt.SetDataSource(ds.Tables(1))    'I am having the error at here

 

        CrystalReportViewer1.ReportSource = rpt

        CrystalReportViewer1.Refresh()

    End Sub

End Class

Open in new window

0
Comment
Question by:kamikazis
  • 3
7 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 24383213
you normally provide the full dataset to a report, not just a table.

also, the table collections is 0-based. so if you want to access the first table, you need to provide the index 0 (ds.tables(0))

Finally, have a look at http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
0
 

Author Comment

by:kamikazis
ID: 24394107
hi emoreau, ur page is very useful... Now i overcame this error...Now its executing correctly...But i want to display a crystal report as user desire by giving his choices in a vb form....I want to learn about grouping also..i tried gouping but nothing comes in CR...  Plz help me  Eric....
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24394168
>>But i want to display a crystal report as user desire by giving his choices in a vb form

I have explained that in my article. See the "Passing a value to a parameter of the report" section.

For grouping, have a look at http://www.businessobjects.com/global/pdf/dev_zone/VS2005_Walkthroughs.pdf
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24395005
What user choices?  What will the choices do?

mlmcc
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 25447831
I think I put kamikazis on the right track
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now