4816
社区成员
<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>
//获得数据
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();
//获得数据
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>
//获得数据
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]