VS2010 mvc2 使用rdlc报表

chxg99 2014-07-14 05:12:45
1、建立数据集,
2、建立报表
3、建立页面:

<form id="form1" runat="server">

<h2>RdlcView</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(集合)" WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt" Width="824px">
<LocalReport ReportPath="Reports\Report.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="MvcAppDemo.Reports.DataSet1TableAdapters.stuinfoTableAdapter">
</asp:ObjectDataSource>
</form>

查询结果为:

无法显示报表和数据。
折腾了好几天了上网查找资料,变换了好多方法结果一样?
如果在页面中添加pag个_load方法,会提示:“尚未为数据源提供数据源实例”?

//获得数据
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "SELECT * FROM info where id='1001'";
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(command);
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/info.rdlc");
ReportDataSource rds = new ReportDataSource("DateSet1", dt.DefaultView);


ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();

期待大牛鼎力相助,指点一二!
...全文
2698 9 打赏 收藏 举报
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
huameilan0202 2015-04-07
  • 打赏
  • 举报
回复
我也是出现过这种情况,太复杂,改用报表软件了,finereport现在用着还不错。
Frank__Hu 2014-09-09
  • 打赏
  • 举报
回复
我也是一样,搞了好几天都显示不出来数据但也不报错,改用第三方报表了
chxg99 2014-07-16
  • 打赏
  • 举报
回复
引用 2 楼 happy09li 的回复:
http://blog.csdn.net/xiaolong85/article/details/5579963
这个文章看了,也检查核实过没有问题
save4me 2014-07-16
  • 打赏
  • 举报
回复
在第16行设置属于源的时候,你用的是DateSet1,而第34行定义的时候是DataSet1。调用的时候打错了吧? Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource("DateSet1", dt.DefaultView); <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
引用 6 楼 chxg99 的回复:
[quote=引用 4 楼 chxg99 的回复:] 现在已经修改成这样的了。报错为:“尚未为数据源“DataSet1”提供数据源实例。” 在mvc2 下的页面代码:

asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	RdlcView
</asp:Content>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        //获得数据
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
        command.CommandType = System.Data.CommandType.Text;
        command.CommandText = "SELECT * FROM stuinfo where xh='0214001'";
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(command);
        System.Data.DataTable dt = new System.Data.DataTable();
        da.Fill(dt);
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/Report.rdlc");
        Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource("DateSet1", dt.DefaultView);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.DataBind();
        ReportViewer1.LocalReport.Refresh();
    }
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>RdlcView</h2>
    <form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
        Font-Size="8pt" InteractiveDeviceInfos="(集合)" WaitMessageFont-Names="Verdana" 
        WaitMessageFont-Size="14pt" Width="767px">
        <LocalReport ReportPath="Reports\Report.rdlc">
            <DataSources>
                <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" >
    </asp:ObjectDataSource>
    </form>
    
</asp:Content>
chxg99 2014-07-16
  • 打赏
  • 举报
回复
[quote=引用 5 楼 save4me 的回复:]

//获得数据
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
        command.CommandType = System.Data.CommandType.Text;
        command.CommandText = "SELECT * FROM info where id='1001'";
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(command);
        System.Data.DataTable dt = new System.Data.DataTable();
        da.Fill(dt);
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/info.rdlc");
        ReportDataSource rds = new ReportDataSource("DateSet1", dt.DefaultView);

        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.DataBind();
        ReportViewer1.LocalReport.Refresh();
[quote=引用 4 楼 chxg99 的回复:] 现在已经修改成这样的了。报错为:“尚未为数据源“DataSet1”提供数据源实例。” 在mvc2 下的页面代码:

asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	RdlcView
</asp:Content>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        //获得数据
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
        command.CommandType = System.Data.CommandType.Text;
        command.CommandText = "SELECT * FROM stuinfo where xh='0214001'";
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(command);
        System.Data.DataTable dt = new System.Data.DataTable();
        da.Fill(dt);
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/Report.rdlc");
        Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource("DateSet1", dt.DefaultView);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.DataBind();
        ReportViewer1.LocalReport.Refresh();
    }
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>RdlcView</h2>
    <form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
        Font-Size="8pt" InteractiveDeviceInfos="(集合)" WaitMessageFont-Names="Verdana" 
        WaitMessageFont-Size="14pt" Width="767px">
        <LocalReport ReportPath="Reports\Report.rdlc">
            <DataSources>
                <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" >
    </asp:ObjectDataSource>
    </form>
    
</asp:Content>
save4me 2014-07-16
  • 打赏
  • 举报
回复

//获得数据
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
        command.CommandType = System.Data.CommandType.Text;
        command.CommandText = "SELECT * FROM info where id='1001'";
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(command);
        System.Data.DataTable dt = new System.Data.DataTable();
        da.Fill(dt);
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/info.rdlc");
        ReportDataSource rds = new ReportDataSource("DateSet1", dt.DefaultView);

        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.DataBind();
        ReportViewer1.LocalReport.Refresh();
引用 4 楼 chxg99 的回复:
[quote=引用 2 楼 happy09li 的回复:] http://blog.csdn.net/xiaolong85/article/details/5579963
这个文章看了,也检查核实过没有问题[/quote]
save4me 2014-07-15
  • 打赏
  • 举报
回复
因为你的是Web项目,所以在ReportViewer1.LocalReport.DataSources.Add(rds);之后,还需要调用ReportViewer1.DataBind();来绑定数据源。
chxg99 2014-07-15
  • 打赏
  • 举报
回复
顶起来,期待大牛出现
发帖
图表区

4816

社区成员

.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
帖子事件
创建了帖子
2014-07-14 05:12
社区公告
暂无公告