ima give this a go. seems logical.
http://weblogs.asp.net/erobillard/ar.../16/37832.aspx Quote:
Because of this:
"At least one element in the source array could not be cast down to the destination array type."
It happens on the: dc.CopyTo(columns,0);
The problem is that SQL Server allows nulls but .NET does not. I tried adjusting your suggestion to use a System.Data.SqlTypes.SqlString array instead, but that just stalls the problem until the Join, as SqlString doesn't provide a Join method.
If there were a way to convert the array from SqlString to String we might be in business, but then we're getting back into less efficient, less readable territory.
Which brings us back to the posted solution. It works fine here, but is not complete if the DataTable contains non-string types like number or dates. Really, there should be a switch (column.GetType()) involved to wrap strings in quotation marks, run numbers through .ToString() and format dates.
Another solution is not to use a dataset at all, but an object class with a ToStringArray method. That makes a Split / Join solution a cinch, and would be an easy thing to add for anyone using CodeSmith (which rocks!). ToStringArray would be a useful method to have around. But the queries I use to produce CDFs, like most reports, are the result of JOINs and I'm not about to generate a data access class for every query I write.
So, back to the posted solution. Any other ideas?
Take care,
Eli.
|