views:

483

answers:

2

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...

A: 

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?

jlech
A: 

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)
John M