I have requirement to export SQL Script data to an excel using C#.Net. Currently I face issue in avoiding duplicat values for columns, when a record has multiple values for a column it should look like as in the bellow, the entire record should not repeated for each values of the column.
should I handle it in application level or in Sql script. please advice me.
Currently I get data set and bind it to a grid view and then do the export to excel function.
for example Sql Data could be
select B.BID, B.BName, M.Year
from tbl_B B
inner join tbl_Master M ON B开发者_StackOverflow社区.BID = fm.BIDFK
where B.BName = 'B9'
Group By B.BID, B.BName, M.Year
And the Result
I have cleared out this issue on C# side, I use nested grid-view to bind multiple valued columns for a record, when exporting to excel clear controls inside the parent grid-view to export data from all grid-view.
I think it need to be done in SQL script. It's not complicated logic to apply .
I would seriously look at using the Report Viewer control and a local report rather than trying to build the Excel sheet by hand. Check out GotReportViewer.com and the examples on the right cover exporting to Excel, and using the control from a console application.
精彩评论