reportdatasource and saving as word file

  • Thread starter Thread starter navigare_
  • Start date Start date
N

navigare_

Guest
i wanna work with a localreport.i bound reportviewer with a datatable as a datasource.once reportviewer display on the screen i want to save the reportviewer as a word file.i tried below code but is give me an error.how can fix it?

String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Applicationservices"].ConnectionString;
SqlConnection con= new SqlConnection(strConnString);

//Get the data from database into datatable
string strQuery = "select *from Customers";
SqlCommand cmd = new SqlCommand(strQuery, con);

// Command nesnesini kullanarak adaptörümüzü olusturuyoruz.
SqlDataAdapter sda = new SqlDataAdapter(cmd);
// bilgi tasiyicisi olarak datatable veya dataset e ihtiyacimiz var
DataTable dt = new DataTable();

try
{
con.Open();//bağlantıyı aç
sda.SelectCommand = cmd;//dataadapter ın çalıştıracağı komutu seç.
sda.Fill(dt);//dataadapter ın seçtiği komutla gelen bilgileri datatable a doldur.
}
catch (Exception ex)
{
throw ex;
}

ReportDataSource datasource = new ReportDataSource("Report1",dt);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.Refresh();



ReportViewer1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=Customers.doc");

Response.Charset = "";
Response.ContentType = "application/vnd.ms-word ";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

ReportViewer1.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

Continue reading...
 
Back
Top