Это мой код, я сделал это для моего проекта, чтобы сгенерировать отчет в формате PDF
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
getreport();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
// base.VerifyRenderingInServerForm(control);
}
public void getreport()
{
string province = Request.QueryString["Province"].ToString();
string district = Request.QueryString["District"].ToString();
string village = Request.QueryString["Village"].ToString();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport rep = ReportViewer1.LocalReport;
rep.ReportPath = @"Report.rdlc";
ReportDataSource dsRep = new ReportDataSource();
dsRep.Name = "DataSet1";
dsRep.Value = GetDataTable(province, district, village);
rep.DataSources.Clear();
rep.DataSources.Add(dsRep);
//ReportViewer1.DocumentMapCollapsed = true;
//ReportViewer1.ShowPrintButton = true;
//rep.Render("PDF");
byte[] result = null;
result = rep.Render("PDF");
Response.ClearContent();
Response.AppendHeader("content-length", result.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(result);
Response.Flush();
Response.Close();
rep.Refresh();
}
protected DataTable GetDataTable(string p,string d,string v)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
DataTable dt;
SqlDataAdapter da;
SqlCommand cmd;
string filter = "";
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
cmd = new SqlCommand("select '" +p + "' as UserName, '"+d+"'Password,'"+ v+"' as category", con);
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
cmd.Dispose();
con.Close();
return dt;
}
catch (Exception ex)
{
return null;
}
}