Solved

How can I display data in crystal report using dataset

Posted on 2008-10-13
6
784 Views
Last Modified: 2012-05-05
I am having problems in the code used to display data of a query into a crystal report, when I conect directly to the database it work fine. The first sample works but the second one it shows me an error on the " rpt.SetDataSource(Ciudad_Table)"

Thanks

This code works.
 
Imports System.Data.SqlClient
 
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim rpt As New CrystalReport1() 'The report you created.
        Dim myConnection As SqlConnection
        Dim MyCommand As New SqlCommand()
        Dim myDA As New SqlDataAdapter()
        Dim myDS As New DataSet() 'The DataSet you created.
        Try
            myConnection = New SqlConnection("Data Source=.\SQLExpress;Integrated Security=SSPI;" & _
                                             "Initial Catalog=DSISacc;")
            MyCommand.Connection = myConnection
            MyCommand.CommandText = "SELECT * FROM M_Ciudad"
            MyCommand.CommandType = CommandType.Text
            myDA.SelectCommand = MyCommand
            myDA.Fill(myDS, "M_Ciudad")
            rpt.SetDataSource(myDS)
            CrystalReportViewer1.ReportSource = rpt
        Catch Excep As Exception
            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class
 
____________________________________________________
 
 Dim Ciudad_Adapter As New DBSaccTableAdapters.M_CiudadTableAdapter
    Dim Ciudad_Table As New DBSacc.M_CiudadDataTable
 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim rpt As New CrystalReport1() 'The report you created.
        Try
 
            Ciudad_Adapter.Fill(Ciudad_Table)
            rpt.SetDataSource(Ciudad_Table)
            CrystalReportViewer1.ReportSource = rpt
 
        Catch Excep As Exception
            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
 
End Class

Open in new window

0
Comment
Question by:Celorza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 22703891
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 22703894
0
 

Author Comment

by:Celorza
ID: 22743857
Emoreau,

Thank, I have read your article, but I am lost in how to fill the report. I usualy

Dim Ciudad_Adapter As New DBSaccTableAdapters.M_CiudadTableAdapter
Dim Ciudad_Table As New DBSacc.M_CiudadDataTable
Private mrptDoc as new ReportDocument
 
Ciudad_Adapter.Fill(Ciudad_Table)
mrptDoc.Load("c:\dis\e-solutions\DSISacc\Cartera.rpt")
mrptDoc.SetDataSource(Ciudad_Table)
crystalReportViewer1.ReportSource = mrptDoc

But I get an error in the setdatasource it does not admint "Ciudad_Table"

Thanks for your help.

carlos
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 22744099
SetDataSource requires a Dataset not a datatable.
0
 

Author Comment

by:Celorza
ID: 22744323
Emoreau,

But if I put the dataset of my proyect also appear as an error, Sorry but I totaly lost. Can you helpme to understand my problem.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 22744581
it would really help me if you could tell me what error you have? where and how is your dataset is declared? how is it filled? I see a tableadapter and a datatable in your code but no trace of a dataset!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET (VB) return a record 2 52
make control visible based off other control value 7 24
Need help with a query 14 40
How can I add google maps in vb.net. 2 24
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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