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 6967321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:18:21+00:00 2026-05-27T16:18:21+00:00

May I know what’s wrong with my code below.. ’cause it doesn’t show the

  • 0

May I know what’s wrong with my code below.. ’cause it doesn’t show the result. I want to view the name of employees, their number of activities per month, then their average grade by dividing the num. of activities to their score. I hope you can help me to do this. I want to view it on list box

the format is this:

Juan Dela Cruz
Count: 10    
Score: 5
Grade: 2

econ = new SqlConnection();
econ.ConnectionString = emp_con;
econ.Open();
int found = -1;
string Log_User, Count, Score;
int iGrade = 0;
string n = "";
string strScore = "Score: ";
string strGrade = "Grade: ";
string strCount = "Count: ";
ecmd = new SqlCommand("SELECT Log_User, Count = COUNT(Det_Score), Score = SUM(Det_Score) FROM MEMBER M,DETAILS D WHERE D.Emp_Id = M.Emp_Id AND Month(Sched_Start) like" + "'" + comMonth.Text + "'AND Year(Sched_Start) like" + "'" + txtYear.Text + "'GROUP BY Log_User", econ);
ecmd.CommandType = CommandType.Text;
ecmd.Connection = econ;
dr = ecmd.ExecuteReader();
listBox1.Text = txtYear.Text;
listBox1.Text = comMonth.Text;
while (dr.Read())
{
 Log_User = (string)dr["Log_User"];
 Count = (string)dr["Count"];
 Score = (string)dr["Score"];
 iGrade = Convert.ToInt32(Count) / Convert.ToInt32(Score);
 found += 1;
 listBox1.Items.Insert(found, Convert.ToString(n));
 listBox1.Items.Insert(found, Convert.ToString(strGrade) + Convert.ToString(iGrade));
 listBox1.Items.Insert(found, Convert.ToString(strScore) + Convert.ToString(Score));
 listBox1.Items.Insert(found, Convert.ToString(strCount) + Convert.ToString(Count));
 listBox1.Items.Insert(found, Convert.ToString(Log_User));
 listBox1.Items.Insert(found, Convert.ToString(n));
}

econ.Close();
}
catch (Exception x)
{
  MessageBox.Show(x.GetBaseException().ToString(), "Connection Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

I want to view the result here but I can’t see the output. Is there any problem in my sql statement?? In MS SQL 2005 when I run the sql, it run smoothly but when I run it to VS 2010, it doesn’t appear.

  • 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-27T16:18:22+00:00Added an answer on May 27, 2026 at 4:18 pm
    listBox1.Items.Clear();
    listBox1.Text = "";
    econ = new SqlConnection();
    econ.ConnectionString = emp_con;
    econ.Open();
    float iGrade = 0;
    float Grade = 0.00F;
    string Log_User;
    float Count, Score;
    string n = "";
    string strScore = "Score: ";
    string strGrade = "Grade: ";
    string strCount = "Count: ";
    string date = DateTime.Now.ToShortTimeString();
    ecmd = new SqlCommand("SELECT Log_User, Count = COUNT(Det_Score), Score = SUM(Det_Score) FROM MEMBER M,DETAILS D WHERE D.Emp_Id = M.Emp_Id AND Log_User like" + "'" + Convert.ToString(comEmployee.Text) + "'AND Month(Sched_Start) =" + "'" + Convert.ToInt32(iMonth) + "'AND Year(Sched_Start) =" + "'" + Convert.ToInt32(txtYear.Text) + "'GROUP BY Log_User", econ);
    ecmd.CommandType = CommandType.Text;
    ecmd.Connection = econ;
    dr = ecmd.ExecuteReader();
    listBox1.Items.Add("As of " + date + ": "+ comMonth.Text + ", "+ txtYear.Text);
    while (dr.Read())
    {
       if (dr == null || !dr.HasRows)
       {
          MessageBox.Show("No record found.", "Error");
       }
       else
       {
          Log_User = (string)dr["Log_User"];
          Count = (dr["Count"] as int?) ?? 0;
          Score = (dr["Score"] as int?) ?? 0;
          try
          {
             iGrade = Score / Count;
             Grade = iGrade * 100;
          }
          catch (DivideByZeroException)
          {
              Console.WriteLine("Exception occured");
          }
          listBox1.Items.Add(Convert.ToString(n));
          listBox1.Items.Add(Convert.ToString(Log_User));
          listBox1.Items.Add(Convert.ToString(strCount + Count));
          listBox1.Items.Add(Convert.ToString(strScore + Score));
          listBox1.Items.Add(Convert.ToString(strGrade + Grade));
          }
       }               
       econ.Close();
    

    the code above is my answer for my question..I hope it can help others. Thanks to those people who helped me to figured it out.. 😀 God bless

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you may know, Silverlight 3 doesn't support IMultiValueConverter and... I badly need it.
As you may know, when we have this code in Javascript : function getName()
You may know the Windows compliance tool that helps people to know if their
As you may know, elements that contain floating elements won't stretch around their child
As all of you may know, Java code is compiled and interpreted by JVMs.
As some of you may know, Microsoft banned memcpy() from their Security Development Lifecycle
You may know this recommendation from Microsoft about the use of exceptions in .NET:
You may know the scriptaculous SlideUp effect . Well, It slides up a div
As you may know, in VS 2008 ctrl + tab brings up a nifty
As some of you may know, use of the LIMIT keyword in MySQL does

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.