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.
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