Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 981
  • Last Modified:

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

0
mrong
Asked:
mrong
  • 13
  • 10
1 Solution
 
É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
Industry Leaders: 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!

 
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
 
Éric MoreauSenior .Net ConsultantCommented:
my recommandation: points to emoreau
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 13
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now