在数据库列中添加值 [英] Adding values in a database column
问题描述
我的c#项目中有一个数据库表,这个表包含UserID列,questionID列和Marks_Scored列。
有一系列用户回答的多项选择题,每个核心答案都有一个分数,这个分数输入到marks_scored栏。让我们说如果有10个问题并且用户回答了所有这些问题,我如何在marks_scored列中添加所有10个已回答的问题并显示总数?
我可以查询已回答的问题(如下图所示)但我仍然坚持如何总结已回答的问题..你能帮忙吗?
Hi,
I have got a database table in my c# project, this table contains a UserID column,questionID column and a Marks_Scored column.
there is a series of multiple choice question that the user answers and for every coreect answer there is a score to it, and this score is entered in the marks_scored column. Lets say if there were 10 questions and the user answered all of them , How can I add up all the 10 answered questions in the marks_scored column and display the total?
I can query the answered questions (as shown below) but I am stuck on how I can total the answered question .. Can you please help?
Query = "SELECT * FROM TblQuestions WHERE Id = '"+questionid+"'";
theReader = conn.ExecuteStatement(Query);
while(theReader.Read())
{
score = theReader["marks_scored c"].ToString();
Thank you
}
推荐答案
试试这个...... br $>
try this....
Query = "SELECT SUM(marks_scored c) AS totalMarks FROM TblQuestions WHERE UserID = '"+@UserID+"'";
theReader = conn.ExecuteStatement(Query);
while(theReader.Read())
{
score = theReader["totalMarks"].ToString();
Thank you
}
这篇关于在数据库列中添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!