namespace 报表测试1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {        }        private void button1_Click(object sender, EventArgs e)
        {
            DataTable t_tab = new DataTable();
            t_tab.Columns.Add("日期78",typeof(string));
            t_tab.Columns.Add("房号56", typeof(string));            t_tab.Rows.Add("703", "20090213");
            t_tab.Rows.Add("705", "20090246");
            t_tab.Rows.Add("1005", "20090228");            Source tab = new Source(t_tab);            SourceBindingSource.DataSource = tab.getSource;
            this.reportViewer1.RefreshReport();
        }
    }    class Source
    {
        public DataTable _table = new DataTable();
        public Source(DataTable tab)
        {
            _table = tab;
        }        public DataTable getSource
        {
            get
            {
                return _table;
            }
        }        public DataColumn 日期
        {
            get
            {
                return _table.Columns[0];
            }
        }
        public DataColumn 房号
        {
            get
            {
                return _table.Columns[1];
            }
        }
    }
}本贴昨天已发过,上面的代码是经过大家帮助而修正的代码
新的问题又发生:表身数据无任何显示。
可以肯定的是 tab.getSource 已获得数据
我想是不是DataColumn作为属性返回为问题?昨天问题地址:
http://topic.csdn.net/u/20090217/17/91b7a05d-c782-4ad9-9b3c-a0394e1a7bc8.html

解决方案 »

  1.   

    private void button1_Click(object sender, EventArgs e)
            {
                DataTable t_tab = new DataTable();
                t_tab.Columns.Add("日期78", typeof(string));
                t_tab.Columns.Add("房号56", typeof(string));            t_tab.Rows.Add("703", "20090213");
                t_tab.Rows.Add("705", "20090246");
                t_tab.Rows.Add("1005", "20090228");            Source tab = new Source(t_tab);            SourceBindingSource.DataSource = tab.getSource;
                //this.reportViewer1.RefreshReport();
            }
        }    class Source
        {
            public DataTable _table = new DataTable();
            public Source(DataTable tab)
            {
                _table = tab;
            }        public DataTable getSource
            {
                get
                {
                    return _table;
                }
            }        public DataColumn 日期
            {
                get
                {
                    return _table.Columns[0];
                }
            }
            public DataColumn 房号
            {
                get
                {
                    return _table.Columns[1];
                }
            }
        } 有数据啊。
    this.reportViewer1.RefreshReport();这句话做什么操作?
      

  2.   

    没有做 DataBind()  把
      

  3.   

    在    SourceBindingSource.DataSource = tab.getSource; 后面加上
    reportViewer1.Databind()注释掉   this.reportViewer1.RefreshReport(); 
      

  4.   

    无语
    reportViewer1.根本没有Databind() 方法
    这样的答案也能说出来
    无语
      

  5.   

    http://msdn.microsoft.com/zh-cn/library/ms251784(VS.80).aspx
    你看看这篇文章,开始恢复没有明白你的意思。
    应该是reportViewer1对应的Report1.rdlc没有绑定数据源,所以不行。
    开始以为SourceBindingSource这个是datagridview,所以引起误解,
    第一次使用reportViewer1,
    reportViewer1用起来确实很麻烦。不过你说话很伤人,大家都是在CSDN上学习。
      

  6.   

    要做一些关联,把  reportViewer1和数据对象关联起来。
    reportDataSource1.Name = "WindowsApplication1_Source";
                reportDataSource1.Value = this.sourceBindingSource1;
             
                this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);            this.reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.Report1.rdlc";