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

  • Home
  • SEARCH
  • 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 3420904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:03:26+00:00 2026-05-18T06:03:26+00:00

I am developing a web application using c#. I am reading some data from

  • 0

I am developing a web application using c#. I am reading some data from database to a data table named dt . Sample data is shown below.

agentName  WeekNumber Score 
John       3          45
John       5          78
John       6          33

I want to make some change in the above data based on some conditions. Cause i want to draw a graph based on this data.The agent name is always same.and the week field is unique. I want to make a new data table using conditions listed below.

1-The new data table week field must start from 1.If there is no entry in the data table for week 1, you can add the data into new data table as shown below

John 1  0

it means just give 0 as score.

2-If there is any missing weeks from second row onwards in the data table obtained from database , add the row for that week with score as -1.
in the above example after first row there is a missing week 4. so add it to new data table with score -1

the new data tab;e for sample data is shon below

agentName WeekNumber Score
John      1          0
John      2          0
John      3          45
John      4         -1
John      5         78
John      6         33

How can i do it in an efficient method using c#? The number of rows will vary .
I want to do it using c# . not by using queries because of some reason

  • 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-18T06:03:26+00:00Added an answer on May 18, 2026 at 6:03 am

    you can use the following class and the build a new table from it.

    class AgentsData
    {
        public static DataTabe ProcessDataTabe(DataTable dt)
        {
            Dictionary<string, AgentData> data = new Dictionary<string, AgentData>();
    
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name = dt.rows[i][0].ToString();
                if (!data.ContainsKey(name))
                    data.Add(name, new AgentData);
                int week = Convert.ToInt32(dt.rows[i][1]);
                int score = Convert.ToInt32(dt.rows[i][2]);
    
                data[name].Add(week, score);
            }
    
            foreach (vat agentData in data.Values)
                agentData.Process();
    
            //now build new data table from dictionary and return it
        }   
    }
    
    class AgentData
    {
        public AgentData(string name)
        {
            Name = name;
            WeekScore = new Dictionary<int,int>();
        }
    
        public void Add(int weekNumber, int score)
        {
            WeekScore[weekNumber] = score;
        }
    
        public void Process()
        {
            int min = WeekScore.Keys.Min();
            int max = WeekScore.Keys.Max();
    
            for (int i = 0; i < min; i++)
                WeekScore.Add(i, 0);
    
            for (int i = min + 1; i < max; i++)
                if (!WeekScore.ContainsKey(i))
                    WeekScore.Add(i, -1);
        }
    
        public string Name {get; private set;}  
        public Dictionary<int, int> WeekScore { get; private set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web- application using NHibernate. Can you tell me how to write
I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have
I am tasked with developing a web application and am thinking of using the
I'm using JQuery and Prototype in this web application that I'm developing. I'm looking
I am developing a new web application using .NET 3.5 and SQL Server 2008
I am developing a web application using vs2008 and used two accounts on Vista
I am developing web-application using Google Maps API and ASP.NET Ajax. Here is my
I'm developing web application using CodeIgniter. All this time, I put the custom js
I am developing web application using asp.net, but i want to work on asp
I am developing a web application which has Chart Controls. I have developed a

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.