We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Column aliased in ResultSet is not aliased in DataTable


I have a question on instantiating a new DataTable with a ResultSet that has column aliases. When we attempt to do this, the column alias name appears to be dropped in favor of the original query column name in the DataTable, although admittedly it is difficult to tell when debugging obfuscated code. Here's a code sample...

String query = "SELECT last_nm \"Last Name\" from hazel.pers_names where last_nm = \"SMITH\"";
PreparedStatement pStmt = conn.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = pStmt.executeQuery();
DataTable dt = new DataTable(resultSet);

When I dig into the ResultSet, I can see the properties columnName=Last Name, originalColumnName=LAST_NM in the debugger. However, the only DataColumn element in the DataTable under the DataColumnCollection is an entry of "LAST_NM", not "Last Name". In practice, we've found that when using DataTables, only the non-aliased columns in our SQL will be in the document after the mail merge. Is there a special approach for handling column aliases and DataTables we should be using? I've tried various forms of aliasing (no ticks, single ticks, double ticks) and haven't found a solution.

Thanks, John

Hi John,

Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v14.3.0, I am unable to reproduce this problem on my side. Please check the attached image for detail.

I would suggest you please upgrade to the latest version of Aspose.Words i.e. v14.3.0 and let us know how it goes on your side. I hope, this will help.

Thank you for your reply. After further investigation, it appears to be an issue with our version of MySQL and our db connector not playing nicely with column aliases in the query.

Hi John,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.