报表查看器使用C#和Access数据库

时间:2014-07-06 07:47:40

标签: c# database ms-access report reportviewer

我想在数据库访问中检索某个表中的某些数据,但每当我从数据库中检索数据时,它只会给我一个空白数据。这里更详细的是我的代码

private void simpleButton1_Click_1(object sender, EventArgs e)
    {
        if (cboSearch.Text == "ALL")
        {
            DataTable dt = new DataTable();
            try
            {
                OleDbConnection Con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\MotoFix.mdb");

                OleDbCommand Com = new OleDbCommand();
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                Con.Open();
                Com.Connection = Con;

                if (true)
                {
                    Com.CommandText = String.Format("SELECT prodCode as [Code], prodName as [Name], prodDescription as [Description], prodBrand as [Brand], prodSRP as [Product Price], sCategory as [Category] FROM Product");
                    adapter.SelectCommand = Com;
                    adapter.Fill(dt);
                }

                this.productBindingSource.DataSource = dt; 
                this.reportViewer1.RefreshReport(); 
                Con.Close();
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

0 个答案:

没有答案