Crystal Reports 2008 / .Net DataTable with Spaces in Column Names

Posted by Blake on 12/30/2009
)

I needed to take an existing .Net DataTable that exists in a program we have and feed it to Crystal Reports. To do this, I went the route of creating an XML file that corresponded to the columns in the DataTable, point Crystal to that and then place the elements on the form. The only problem was, this specific table had spaces in the column names and for outside circumstances, it could not be changed and XML does not accept spaces in tag names. The answer, use XML’s escape character for the space. Let’s say I have a DataTable with these two fields:

First Name, Last Name

It’s corresponding XML would look something like this (this would show as the ‘people’ table of the data source):

    <?xml version="1.0" encoding="utf-8" ?>
    <people>
        <first_x0020_name>
            <last_x0020_name>
    </people>