C# 从数据库中计算正确回答的数量
这里,尽管包含正确答案,输出p始终为零C# 从数据库中计算正确回答的数量,c#,mysql,asp.net,.net,C#,Mysql,Asp.net,.net,这里,尽管包含正确答案,输出p始终为零 DataTable dt = bllSco.GetAllScore(SubId, UserId); int n = dt.Rows.Count; int p = 0, m = 0; for (int i = 0; i < n; i++) { string check = dt.Rows[i]["remark"].ToString(); if (check == "Correct")
DataTable dt = bllSco.GetAllScore(SubId, UserId);
int n = dt.Rows.Count;
int p = 0, m = 0;
for (int i = 0; i < n; i++)
{
string check = dt.Rows[i]["remark"].ToString();
if (check == "Correct")
{
p = p + 1;
}
else
{
m = m + 1;
}
}
lblTotal.Text = n.ToString();
lblCorrect.Text = p.ToString();
lblIncorrect.Text = m.ToString();
DataTable dt=bllSco.GetAllScore(SubId,UserId);
int n=dt.Rows.Count;
int p=0,m=0;
对于(int i=0;i
您应该使用如下sql代码:
select count(1) FROM table where col='Correct';
然后fetch
结果为array
,并且arr[0]
是您想要的号码。试试这个
SELECT COUNT(column_name) FROM table_name;
您可以获得该列记录的计数,以获取更多信息使用可能
检查
是否不正确
?您是否调试了代码并检查了值?在调试模式下,检查的值是多少?如果p=0,则无路检查==“正确”。检查既正确又不正确