开发者

How to avoid duplicate entries of a record when Exporting SQL server data to an Excel in C#?

开发者 https://www.devze.com 2023-04-06 12:03 出处:网络
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 lik

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.

How to avoid duplicate entries of a record when Exporting SQL server data to an Excel in C#?

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

How to avoid duplicate entries of a record when Exporting SQL server data to an Excel in C#?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号