Using the GiosPDF Library in a ASP .NET 3.5开发者_运维问答 web application. The library examples use a datatable to populate a PDF table. All my data is in various SQLDataSources. How do I convert/cast the SqlDataSource into a Datatable?
I tried this:
DataView sdsLateRoutesDV = new DataView();
DataTable sdsLateRoutesDT = new DataTable();
sdsLateRoutesDV = (DataView)sdsLateRoutes_long.Select(DataSourceSelectArguments.Empty);
sdsLateRoutesDT = sdsLateRoutesDV.ToTable();
But it crashes...
What I came up with was:
/* create dataview from sql data source */
DataView dv = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty);
/* convert dataview to datatable */
DataTable dt = dv.ToTable();
/* create new PDF table */
PdfTable pt = myPdfDocument.NewTable(FontRegular,1,1,1);
/* import datatable into PDF table */
pt.ImportDataTable(dt)
Your code is fine, as the conversion is allowed. The error is happening somewhere along the line after the data conversion. Maybe check to see if the table's schema is correct or if there's some bad data that the library is not liking?
精彩评论