report 与 datatable 的绑定问题 再度求解

jcyluck 2009-02-18 10:33:04
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
...全文
113 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
贫僧又回来了 2009-02-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jcyluck 的回复:]
楼上二位在浪废CSDN的空间
[/Quote]
自己有问题来问还这么拽!你这种态度以后就别来问了,谁愿意搭理你啊!
jcyluck 2009-02-19
  • 打赏
  • 举报
回复
晕菜
我用VS2008
谢谢
对不起
jcyluck 2009-02-18
  • 打赏
  • 举报
回复
楼上二位在浪废CSDN的空间
lxf2000104 2009-02-18
  • 打赏
  • 举报
回复
日期78 房号56
703 20090213
705 20090246
1005 20090228
确实有数据的
lxf2000104 2009-02-18
  • 打赏
  • 举报
回复
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();这句话做什么操作?
lxf2000104 2009-02-18
  • 打赏
  • 举报
回复
要做一些关联,把 reportViewer1和数据对象关联起来。
reportDataSource1.Name = "WindowsApplication1_Source";
reportDataSource1.Value = this.sourceBindingSource1;

this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);

this.reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.Report1.rdlc";
lxf2000104 2009-02-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jcyluck 的回复:]
楼上二位在浪废CSDN的空间
[/Quote]

[Quote=引用 7 楼 jcyluck 的回复:]
无语
reportViewer1.根本没有Databind() 方法
这样的答案也能说出来
无语
[/Quote]
说话很伤人啊!
lxf2000104 2009-02-18
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/ms251784(VS.80).aspx
你看看这篇文章,开始恢复没有明白你的意思。
应该是reportViewer1对应的Report1.rdlc没有绑定数据源,所以不行。
开始以为SourceBindingSource这个是datagridview,所以引起误解,
第一次使用reportViewer1,
reportViewer1用起来确实很麻烦。不过你说话很伤人,大家都是在CSDN上学习。
jcyluck 2009-02-18
  • 打赏
  • 举报
回复
无语
reportViewer1.根本没有Databind() 方法
这样的答案也能说出来
无语
YouJason 2009-02-18
  • 打赏
  • 举报
回复
在 SourceBindingSource.DataSource = tab.getSource;

后面加上
reportViewer1.Databind()

注释掉 this.reportViewer1.RefreshReport();
wugencao520 2009-02-18
  • 打赏
  • 举报
回复
没有做 DataBind() 把
EveryCase 2009-02-18
  • 打赏
  • 举报
回复
帮你顶一个吧

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧