使用vs 2013显示带有访问数据库的水晶报告

时间:2015-11-18 08:10:58

标签: c# crystal-reports

我是编程新手,我使用数据集和水晶报表查看器创建了一个带访问数据库的WFP csharp程序,其中有两个报表。其中一个报告显示,而另一个显示空列,我已经重新检查连接字符串,一切似乎都很好,这里是一个示例代码,rptCustomers是显示数据来自db和rptSales显示空行的那个,是吗我做错了什么

private void btnCustRpt_Click_1(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                timer1.Enabled = true;
                rptCustomers rpt = new rptCustomers();
                //The report you created.
                cmd = new OleDbCommand();
                OleDbDataAdapter myDA = new OleDbDataAdapter();
                SIS_DBDataSet myDS = new SIS_DBDataSet();
                //The DataSet you created.
                con = new OleDbConnection(cs);
                cmd.Connection = con;
                cmd.CommandText = "SELECT * from Customer order by CustomerName";
                cmd.CommandType = CommandType.Text;
                myDA.SelectCommand = cmd;
                myDA.Fill(myDS, "Customer");
                rpt.SetDataSource(myDS);
                frmCustomersReport frm = new frmCustomersReport();
                frm.crystalReportViewer1.ReportSource = rpt;
                frm.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            {
                try
                {
                    Cursor = Cursors.WaitCursor;
                    timer1.Enabled = true;
                    rptSales rpt = new rptSales();
                    //The report you created.
                    cmd = new OleDbCommand();
                    OleDbDataAdapter myDA1 = new OleDbDataAdapter();
                    SIS_DBDataSet myDS1 = new SIS_DBDataSet();
                    //The DataSet you created.
                    con = new OleDbConnection(cs);
                    cmd.Connection = con;
                    cmd.CommandText = "SELECT * from Sales order by CustomerID";
                    cmd.CommandType = CommandType.Text;
                    myDA1.SelectCommand = cmd;
                    myDA1.Fill(myDS1, "Sales");
                    rpt.SetDataSource(myDS1);
                    frmSalesReport frm = new frmSalesReport();
                    frm.crystalReportViewer1.ReportSource = rpt;
                    frm.Visible = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

0 个答案:

没有答案