exportar crystal reports
Publicado por emarin (3 intervenciones) el 28/03/2007 13:19:24
hola, escribo porq tengo un problema exportando los crystal reports y no se como solucionarlo.... creo un reporte dependiendo unos datos de entrada del usuario, el reporte se crea perfecto pro cuando le doy al boton de exportar me dice q hay un error de conexion con el reporte... anexo mi codigo a ver si alguien ve el error q estoy cometiendo y puede ayudarme, gracias de antemano
public Trabajador Rel = new Trabajador();
public void generar_reporte(string StrSql,CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer)
{
StrConn = "Data Source=alcasa27;Initial Catalog = NT3400;User Id = UsrPrueba;Password=usrprueba" ;
SqlConn = new System.Data.SqlClient.SqlConnection(StrConn) ;
myCommand = new System.Data.SqlClient.SqlCommand(StrSql,SqlConn);
SqlConn.Open() ;
objDataSet.DataSetName = "Reportes";
Dataadapter= new System.Data.SqlClient.SqlDataAdapter(StrSql, SqlConn);
Dataadapter.SelectCommand=myCommand;
Dataadapter.Fill(objDataSet);
// Crea el reporte
// Asocia el conjunto de datos con el reporte
Rel.SetDataSource(objDataSet.Tables[0]);
// Asocia el reporte con el Visualizador
CrystalReportViewer.ReportSource = Rel;
objDataSet.Clear();
SqlConn.Close();
}
public void exportar()
{
System.IO.MemoryStream rptStream = new System.IO.MemoryStream();
rptStream = ((System.IO.MemoryStream)(Rel.ExportToStream(ExportFormatType.PortableDocFormat )));
//Limpiamos la memoria
Response.Clear();
Response.Buffer = true;
//Le indicamos el tipo de documento que vamos a exportar
Response.ContentType = FormatoDocumento();
//Automaticamente se descarga el archivo
Response.AddHeader("Content-Disposition", "attachment;filename=" + this.nombre);
//Se escribe el archivo
Response.BinaryWrite(rptStream.ToArray());
Response.End();
}
public string FormatoDocumento()
{
public Trabajador Rel = new Trabajador();
public void generar_reporte(string StrSql,CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer)
{
StrConn = "Data Source=alcasa27;Initial Catalog = NT3400;User Id = UsrPrueba;Password=usrprueba" ;
SqlConn = new System.Data.SqlClient.SqlConnection(StrConn) ;
myCommand = new System.Data.SqlClient.SqlCommand(StrSql,SqlConn);
SqlConn.Open() ;
objDataSet.DataSetName = "Reportes";
Dataadapter= new System.Data.SqlClient.SqlDataAdapter(StrSql, SqlConn);
Dataadapter.SelectCommand=myCommand;
Dataadapter.Fill(objDataSet);
// Crea el reporte
// Asocia el conjunto de datos con el reporte
Rel.SetDataSource(objDataSet.Tables[0]);
// Asocia el reporte con el Visualizador
CrystalReportViewer.ReportSource = Rel;
objDataSet.Clear();
SqlConn.Close();
}
public void exportar()
{
System.IO.MemoryStream rptStream = new System.IO.MemoryStream();
rptStream = ((System.IO.MemoryStream)(Rel.ExportToStream(ExportFormatType.PortableDocFormat )));
//Limpiamos la memoria
Response.Clear();
Response.Buffer = true;
//Le indicamos el tipo de documento que vamos a exportar
Response.ContentType = FormatoDocumento();
//Automaticamente se descarga el archivo
Response.AddHeader("Content-Disposition", "attachment;filename=" + this.nombre);
//Se escribe el archivo
Response.BinaryWrite(rptStream.ToArray());
Response.End();
}
public string FormatoDocumento()
{
Valora esta pregunta


0