custom dataset for CrystalReport in Visual Studio 2005

Greeting,

I used Visual Studio 2005 to create a web application. I want to use my own dataset instead of those provided by CrystalReport. But the report is still using the auto-bind data from the report. It doesn't take my dataset(ds). PLease see my code below and let me know if you have any thoughts.

dim ds As New System.Data.dataSet()
adapter.Fill(ds)

Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
rpt.Load(Server.MapPath("CrystalReport1.rpt"))
rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource=rpt

mrongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Hi mrong,

what is the error message?

when you created your report, did you create it using a schema file (.xsd)?

Cheers!
0
mrongAuthor Commented:
I didn't get any error message. I got the report, but the data on the report is NOT from my dataset. When I created the report, it did add database connection and SQL statement. I think the CrystalReport auto bind the data instead of using the dataset I fill in page-load function.

I tested to use the same dataset for GridView and it used my dataset, but CrystalReportViewer doesn't use my dataset. I am confused.........

Thanks.
0
Éric MoreauSenior .Net ConsultantCommented:
>>When I created the report, it did add database connection and SQL statement. I think the CrystalReport auto bind the data instead of using the dataset I fill in page-load function

I don't think you can replace data that is bound to the database.

See http://support.businessobjects.com/library/kbase/articles/c2010929.asp
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

mrongAuthor Commented:
emoreau,


So I can use my own dataset to create schema and use it for CrystalReport? Thank you for the link your provided, but I need little bit more detail on how to do it.

Here is what I want. I want to create my own dataset and use CrystalReportViewer(with my dataset) to view the CrystalReport.

Thanks.
0
Éric MoreauSenior .Net ConsultantCommented:
>>So I can use my own dataset to create schema and use it for CrystalReport?

Yes.


>>Thank you for the link your provided, but I need little bit more detail on how to do it.

After you created your report using the XML schema, you use the code you provided first (rpt.SetDataSource(ds)) to pass current dataset to the report
0
Éric MoreauSenior .Net ConsultantCommented:
0
mrongAuthor Commented:
I followed the instruction from the link you provided. But got no record on the report.
0
Éric MoreauSenior .Net ConsultantCommented:
Retry it. I use this method and it works. I hope you didn't try to convert your actual report. Build a complete new one. Are you sure you have data in your dataset?
0
mrongAuthor Commented:
Are you also using Viusal Studio 2005?

Thanks.
0
Éric MoreauSenior .Net ConsultantCommented:
>>Are you also using Viusal Studio 2005?

Yes and no.

Yes I do use VS 2005 but no I haven't started using CR in VS 2005.
0
mrongAuthor Commented:
Could you please walk me thru? I am new to Visual Studio. Thanks.
0
mrongAuthor Commented:
I am using a web application. So I have to create a Helper Class to populate the DataSet.
Did you do the same?

Thanks.
0
Éric MoreauSenior .Net ConsultantCommented:
The way the dataset is created is really not important. Once you have a dataset, create a schema from it and build your report on the schema.
0
mrongAuthor Commented:
OK. I created a dataset in my web app. How to create a schema from it?

Thanks
0
Éric MoreauSenior .Net ConsultantCommented:
You can use the WriteXmlSchema of the dataset object

myDataSet.WriteXmlSchema ("c:\MySchema.xsd")
0
mrongAuthor Commented:
I have create DataSet1 and I can preview the data. Then I create a new report which base on the dataset schema. My VB code is the following. I got no record show up on my report. Thanks.

Dim MyOracleDS As New DataSet1()
        MyOracleAdapt.Fill(MyOracleDS)
        Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        rpt.Load(Server.MapPath("CrystalReport.rpt"))
        rpt.SetDataSource(MyOracleDS)
        CrystalReportViewer1.ReportSource = rpt
0
Éric MoreauSenior .Net ConsultantCommented:
Any error message?

You should try with a Windows forms. It is often easier to debug.
0
mrongAuthor Commented:
no errors
0
Éric MoreauSenior .Net ConsultantCommented:
0
mrongAuthor Commented:
I added a helper class to populate the dataset as the link described. but got the following errors below.


Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.OracleClient
Imports System.Data.DataSet
Imports System.Data.OracleClient.OracleDataAdapter


Public Class DataSetConfiguration
    Private Const Connection_String As String = "Data Source=MyDB;Persist Security Info=True;User ID=ROOT;Password=mypasswd;Unicode=True "
    Private Const Query_String As String = "Select af1,trans_num,trans_item from sc_rut_gasdl_history where trans_num is not null"
    Private Const DATATABLE_NAME As String = "MyTable"
    Private Const Directory_File_Path As String = "C:\Inetpub\wwwroot\InvoiceReport"

    Public Shared ReadOnly Property MyDataSet() As DataSet
        Get

        End Get
    End Property
    Dim myDataSet As DataSet = New DataSet()
   
  myDataSet.ReadXmlSchema(DIRECTORY_FILE_PATH & "MyXMLSchema.xsd")    
 ***error at line above->'myDataSet' declaration expected

    Dim MyOracleConn As New System.Data.OracleClient.OracleConnection(Connection_String)
    Dim MyOracleAdapt As New System.Data.OracleClient.OracleDataAdapter(Connection_String, MyOracleConn)
    MyOracleAdapt.Fill (myDataSet,DATATABLE_NAME)
    ***error at line above->'MyOracleAdapt' declaration expected

    Return myDataSet
   ***error at line above-> statement can't appear outside of method body

End Class
0
Éric MoreauSenior .Net ConsultantCommented:
this has nothing to do with the orignal CR question! Have you been able to reproduce the sample provided in the documentation given?

your code needs to be between the get ... end get:

Public Class DataSetConfiguration
    Private Const Connection_String As String = "Data Source=MyDB;Persist Security Info=True;User ID=ROOT;Password=mypasswd;Unicode=True "
    Private Const Query_String As String = "Select af1,trans_num,trans_item from sc_rut_gasdl_history where trans_num is not null"
    Private Const DATATABLE_NAME As String = "MyTable"
    Private Const Directory_File_Path As String = "C:\Inetpub\wwwroot\InvoiceReport"

    Public Shared ReadOnly Property MyDataSet() As DataSet
        Get

    Dim myDataSet As DataSet = New DataSet()
   
  myDataSet.ReadXmlSchema(DIRECTORY_FILE_PATH & "MyXMLSchema.xsd")    

    Dim MyOracleConn As New System.Data.OracleClient.OracleConnection(Connection_String)
    Dim MyOracleAdapt As New System.Data.OracleClient.OracleDataAdapter(Connection_String, MyOracleConn)
    MyOracleAdapt.Fill (myDataSet,DATATABLE_NAME)

    Return myDataSet

        End Get
    End Property

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
my recommandation: points to emoreau
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.