0

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.

Excel format

for example Sql Data could be

 select B.BID, B.BName, M.Year from tbl_B B inner join tbl_Master M ON B.BID = fm.BIDFK where B.BName = 'B9' Group By B.BID, B.BName, M.Year 

And the Result

enter image description here

1
  • Do I need to go with nested grid view? Commented Sep 23, 2011 at 2:30

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I think it need to be done in SQL script. It's not complicated logic to apply .

4 Comments

Can you please elaborate a bit on how the SQL Query can be constructed?
I think the column should be splited by some delimeter. It's obvious need to be done in store procedure. SP's are compiled and run faster
Yes I do SP. you meant to say that a record should be in a single row and multiple valued columns as string of values spited by delimiter, if so how do we export the data to excel as in the figure?
Please add to the question data that you need to export
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.