T
Thirsty Traveler
I have a dataset that is returned from a sql server select that contains
metadata and a cached dataset saved in an xml column. I would like to
recover the dataset for use in generating a crystal pdf file. the
rptds.ReadXml method can accept either a string file indicating a filename
or a stream. the row["xmldata"].ToString() is the saved dataset. If I use
this directly it throws an error because it is data and not a filename. I
have a workaround seen below that first writes the xml to a temporary
diskfile and then reads it back in in the rptds.ReadXml statement. Although
this works, it is definitely kludgy... there must be a better way.
Any suggestions?
Sample Code:
public static void CreatePDF()
{
DataSet batchds = TestDAL.GetAllBatches();
foreach (DataRow row in batchds.Tables[0].Rows)
{
StreamWriter swtst = new StreamWriter(@"Test.xml", false,
Encoding.Default);
swtst.Write(row["xmldata"].ToString());
swtst.Close();
DataSet rptds = new DataSet();
rptds.ReadXml(@"Test.xml");
TestRpt rpt = new TestRpt ();
rpt.SetDataSource(rptds);
rpt.ExportToDisk(ExportFormatType.PortableDocFormat,
row["FileName"].ToString());
}
}
metadata and a cached dataset saved in an xml column. I would like to
recover the dataset for use in generating a crystal pdf file. the
rptds.ReadXml method can accept either a string file indicating a filename
or a stream. the row["xmldata"].ToString() is the saved dataset. If I use
this directly it throws an error because it is data and not a filename. I
have a workaround seen below that first writes the xml to a temporary
diskfile and then reads it back in in the rptds.ReadXml statement. Although
this works, it is definitely kludgy... there must be a better way.
Any suggestions?
Sample Code:
public static void CreatePDF()
{
DataSet batchds = TestDAL.GetAllBatches();
foreach (DataRow row in batchds.Tables[0].Rows)
{
StreamWriter swtst = new StreamWriter(@"Test.xml", false,
Encoding.Default);
swtst.Write(row["xmldata"].ToString());
swtst.Close();
DataSet rptds = new DataSet();
rptds.ReadXml(@"Test.xml");
TestRpt rpt = new TestRpt ();
rpt.SetDataSource(rptds);
rpt.ExportToDisk(ExportFormatType.PortableDocFormat,
row["FileName"].ToString());
}
}