我正在使用 Asp.net 4.0 和 Sap 水晶报告,我的问题是绑定数据集后无法在 reportViewer 上显示数据。
下面是我的 Aspx 设计器代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="productRepot.aspx.cs" Inherits="ProductionPlanning1.productRepot" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="prdt_Label1" runat="server" Text="ProductID"></asp:Label>
<asp:TextBox ID="matrl_TextBox" runat="server"></asp:TextBox>
<asp:Button ID="rpt_Button1" runat="server" Text="PrintProduct"
onclick="rpt_Button1_Click"></asp:Button>
<CR:CrystalReportViewer ID="product_CrystalReportViewer1" runat="server"
AutoDataBind="true"></CR:CrystalReportViewer>
</asp:Content>
产品报告.aspx.cs
protected void rpt_Button1_Click(object sender, EventArgs e)
{
//DataSet2 DS2 = new DataSet2();
//Fyp_1.Product pp = new Fyp_1.Product();
//DS2.Tables.Add(pp.GetProduct(Convert.ToInt16(matrl_TextBox.Text)).Copy());
//DS2.Tables[0].TableName = "Product";
//CrystalReportProduct TR = new CrystalReportProduct();
//TR.SetDataSource(DS2);
//product_CrystalReportViewer1.ReportSource = TR;
//product_CrystalReportViewer1.DataBind();
GenerateReport();
//DataSet ds = new DataSet();
//BookTicket_Class BT = new BookTicket_Class();
//ds.Tables.Add(BT.GetBookTicketReport(Convert.ToInt16(TicketNO_TextBox.Text)).Copy());
//ds.Tables[0].TableName = "BookTicket";
//TicketReport TR = new TicketReport();
//TR.SetDataSource(ds);
//CrystalReportViewer1.ReportSource = TR;
//CrystalReportViewer1.DataBind();
}
protected void GenerateReport()
{
SqlConnection sqlConn = new SqlConnection(@"Data Source=PROZECK- PC\R2MSSQLSERVER;Initial Catalog=FYP;Integrated Security=True");
SqlCommand comd;
comd = new SqlCommand();
comd.Connection = sqlConn;
comd.CommandType = CommandType.StoredProcedure;
comd.CommandText = "spgetproductNEW";
comd.Parameters.Add("@MaterialID", SqlDbType.Int);
// int VAL = Convert.ToInt32(matrl_TextBox.Text);
if (matrl_TextBox.Text.Trim() != "")
comd.Parameters[0].Value = Convert.ToInt32(matrl_TextBox.Text);
else
comd.Parameters[0].Value = DBNull.Value;
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlAdapter.SelectCommand = comd;
DataSet2 DS2 = new DataSet2();
sqlAdapter.Fill(DS2, "Product");
//oRpt.SetDataSource(ds);
//CrystalReportViewer1.Visible = true;
//CrystalReportViewer1.ReportSource = oRpt;
CrystalReportProduct TR = new CrystalReportProduct();
TR.SetDataSource(DS2);
product_CrystalReportViewer1.ReportSource = TR;
// product_CrystalReportViewer1.DataBind();
}
}
下面是问题的截图给大家描述。
但是当我在水晶报表设计器中检查数据时,它会显示数据
我的第一个绑定数据的代码是这个然后我把它改成上面我粘贴的代码
DataSet2 DS2 = new DataSet2();
Fyp_1.Product pp = new Fyp_1.Product();
DS2.Tables.Add(pp.GetProduct(Convert.ToInt16(matrl_TextBox.Text)).Copy());
DS2.Tables[0].TableName = "Product";
CrystalReportProduct TR = new CrystalReportProduct();
TR.SetDataSource(DS2);
product_CrystalReportViewer1.ReportSource = TR;
product_CrystalReportViewer1.DataBind();