对象引用未设置为对象的实例c#Mysql - >数据集 - > CrystalReport

时间:2017-03-03 17:21:50

标签: crystal-reports dataset

我正在尝试将我的数据从MySqlDatabase显示到我的CrystalReport。我尝试了不同的方法,但仍然得到错误“对象引用没有设置为对象的实例”。

我将我的DataSet命名为ReportDataSet,我还创建了一个完全相同的名称,内容和表格的表格。 DataType作为我的MySqlDatabase。

        MySqlConnection connection;
        MySqlCommand command;
        MySqlDataReader reader;
        MySqlDataAdapter adapter;
        string con = "";

        private void report_Load(object sender, EventArgs e)
        {
            con = "Server = localhost; Database = sample_inventory; Uid = root";
            connection = new MySqlConnection(con);
            connection.Open();

        }
        private void button1_Click(object sender, EventArgs e)
        {

            try
            {

                command = connection.CreateCommand();
                command.CommandText = "select * from tbl_account";
                adapter = new MySqlDataAdapter();
                adapter.SelectCommand = command;
                ReportDataSet ds = new ReportDataSet();
                ds.Clear();
                adapter.Fill(ds, "tbl_account");

                // Create a CrystalReport1
                CrystalReport1 myReport = new CrystalReport1();
                // Set the DataSource 
                myReport.SetDataSource(ds);
                // Report Source to ReportView 
                crystalReportViewer1.ReportSource = myReport; 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

0 个答案:

没有答案