Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3990294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:28:37+00:00 2026-05-20T06:28:37+00:00

I am using the following code to output data from a number of tables

  • 0

I am using the following code to output data from a number of tables in my database to an excel document.

Protected void btnExcelExport_Click(object sender, EventArgs e)
{

string strQuery = "SELECT s.Story, s.StoryCategoryID, CONVERT(VARCHAR(10), 
s.CreationDate, 103) AS CreationDate, m.CompanyRole, af.Name FROM Story s INNER JOIN    
ProjectIterationMember pm ON pm.ProjectIterationMemberID = s.ProjectIterationMemberID 
INNER JOIN Iterations i ON i.ProjectIterationID = pm.ProjectIterationID INNER JOIN 
Member m ON m.MemberID = pm.MemberID INNER JOIN ProjectStoryFactors psf ON psf.StoryID = 
s.StoryID INNER JOIN AgileFactors af ON af.AgileFactorID = psf.AgileFactorID WHERE 
i.ProjectID = '" + proj_id + "'";

SqlCommand cmd = new SqlCommand(strQuery);
DataTable dt = GetData(cmd);

GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=RetroCloud" +  
DateTime.Now.Ticks + ".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

for (int i = 0; i < GridView1.Rows.Count; i++)
{

   GridView1.Rows[i].Attributes.Add("class", "textmode");
}
GridView1.RenderControl(hw);

string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}

The output is as follows:

Story | StoryCategoryID | CreationDate | CompanyRole | Name

negative iii | 1 | 21/02/2011 | Business Analyst | Project Duration
negative iii | 1 | 21/02/2011 | Business Analyst | Team Size
negative iii | 1 | 21/02/2011 | Business Analyst | Process
negative ccc | 1 | 22/02/2011 | Admin | Workspace Layout
negative ccc | 1 | 22/02/2011 | Admin | Organisational and Reporting Structure
negative ccc | 1 | 22/02/2011 | Admin | Process

What I would like to do is 3 things. Many thanks for your help!

1) Change the header names which are clearly coming from the database fields (ie. from StoryCategoryID to Story Type),
2) For StoryCategoryID, if 1 is retrieved – display ‘Negative’ and if 0 is retrieved – display ‘Positive’ instead.
3) Have the output in the following format:

Story | Story Type | Creation Date | Company Role | Tag 1 | Tag 2 | Tag 3

negative iii | 1 | 21/02/2011 | Business Analyst | Project Duration | Team Size | Process
negative ccc | 1 | 22/02/2011 | Admin | Workspace Layout | Organisational | Process
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:28:37+00:00Added an answer on May 20, 2026 at 6:28 am

    You can modify the column names of the data table. Use foreach(DataColumn col in dt.Columns) then use col.ColumnName

    You can access and modify the data for the specific column for your criteria using (Convert.ToInt16(col[n]) != 1)? "Positive" : "Negative" inside a loop. Use dt.Rows.Count for the loop’s condition.

    Hope this helps.

    You can use this inside the foreach loop:

    if (col.ColumnName == "StoryCategoryId") //Or "Story Type"
    for(int rowCount = 0; rowCount < table.Rows.Count; rowCount++)
    {
        col[rowCount] = (Convert.ToInt16(col[rowCount]) == 0) ? "Positive" : "Negative";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to query a database from my jsp, but I'd
I'm using the following code within the JCProperty class to retrieve data from a
I am using following PHP code to connect to MS Access database: $odb_conn =
For the following jQuery code: $(#select).change(function() { $(#output).load(/output/, {}, function(data) { // I want
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I've been using the following code to open Office Documents, PDF, etc. on my
I am currently using the following code to create a web request: Dim myRequest
I'm using the following code, using the SharpZipLib library, to add files to a
I'm using the following code to loop through a directory to print out the
I am using the following code: <?php $stock = $_GET[s]; //returns stock ticker symbol

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.