Click here to Skip to main content
16,004,678 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I got a stored procedure that returns values using a datatable. The returned data looks like:

HTML
Column1    Column2    Column3
 
1          2          John Smith

The problem: I need to assign these values to my .xsd row
HTML
NUMBER1   NUMBER2   CUSTOMER

dt is my datatable, ds is my .xsd dataset.

My Code:
C#
ReportDocument rptCheck = new ReportDocument(); 
            dsCheck ds = new dsCheck(); // .xsd file name 
            DataTable dt = new DataTable(); 
 
             dt = getChecks(); // Sets datatable  
            // Your .rpt file path will be below 
            rptCheck.Load(Server.MapPath("checkprt.rpt"));        
 
            //set dataset to the report viewer. 
            rptCheck.SetDataSource(ds);                  
            CrystalReportViewer1.ReportSource = rptCheck;
Posted
Updated 3-Sep-12 5:06am
v2

may i know why do you wanna store datatable to dataset?
As per your code you want datatable to display records in crystalreport. Here i'll show you some example:

Call this from report form
string sqlQuery ="select * from your table";//put your search condition
adp = new SqlDataAdapter(sqlQuery, connection);
dt = new DataTable();
adp.Fill(dt);
CRViewer cvph = new CRViewer();
cvph.dt = dt;
cvph.Show();


CRViewer form:
It contains a crystalReportViewer named crystalReportViewer1
public partial class CRViewer : Form
    {
        public CRViewer()
        {
            InitializeComponent();
        }
        public DataTable dt = new DataTable();
        private void CRViewer_Load(object sender, EventArgs e)
        {
            CRCustomer crph = new CRCustomer();//CRCustomer is the crystal Report
            crph.Database.Tables[0].SetDataSource(dt);
            crystalReportViewer1.ReportSource = crph;
        }
    }
 
Share this answer
 
I ended up doing it that way and it works. But I'd like to know why it doesn't work by calling the store procedure and using the datatable for the .xsd file. Thx
 
Share this answer
 
v2
Comments
sahabiswarup 5-Sep-12 3:21am    
if you are sharing your code then i can try to find why it is not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900