locked
showing only one record RRS feed

  • Question

  • User1513962562 posted

    I want to show a crystal report on a button click event using data table by passing datatable data to xml but im getting a problem in the report i can see only one record  in the report.

    xml file is showing all data when button is clicked but the report only 1 :(

    below is the click event code.

    protected void btnprint_dest_Click(object sender, ImageClickEventArgs e)
    {
    ReportDocument rptDoc = new ReportDocument();

    dt2.WriteXml(Server.MapPath("dest_rep.xml"), XmlWriteMode.WriteSchema);

    rptDoc.Load(Server.MapPath("dest_rep.rpt"));
    rptDoc.FileName = Server.MapPath("dest_rep.rpt");
    Session["rptDoc"] = rptDoc;
    CrystalReportViewer1.ReportSource = rptDoc;
    CrystalReportViewer1.DataBind();

    }

    Tuesday, December 18, 2012 3:13 AM

All replies

  • User1495804863 posted

    Hi,

     

    You can use ds.WriteXml, but that will require you a Stream to put the output into. If you want the output in a string, try this extension method:

    public static class Extensions
    {
        public static string ToXml(this DataSet ds)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (TextWriter streamWriter = new StreamWriter(memoryStream))
                {
                    var xmlSerializer = new XmlSerializer(typeof(DataSet));
                    xmlSerializer.Serialize(streamWriter, ds);
                    return Encoding.UTF8.GetString(memoryStream.ToArray());
                }
            }
        }
    }

    USAGE:

    var xmlString = ds.ToXml();
    // OR
    Response.Write(ds.ToXml());

    Tuesday, December 18, 2012 3:48 AM