这样求数量对吗(三层结构数据访问层)?
/////////////////存储过程代码:
ALTER PROCEDURE [dbo].[usp_SelectQuestionCountBySubjectID]
@SubjectId int
AS
SELECT count(*)
FROM [dbo].[Question]
WHERE [SubjectId] = @SubjectId
/////////////////数据访问层代码:
         //根据科目编号获取该科目的题目数量
         public int GetQuestionCountBySubjectID(int subjectId)
         {
             int count = 0;
             using (SqlConnection conn = new SqlConnection(connString))
             {
                 SqlCommand objCommand = new SqlCommand(dbOwner + ".usp_SelectQuestionCountBySubjectID", conn);
                 objCommand.CommandType = CommandType.StoredProcedure;
                 objCommand.Parameters.Add("@SubjectId", SqlDbType.Int).Value = subjectId;
                 conn.Open();
                 count = Convert.ToInt32(objCommand .ExecuteScalar());
                 conn.Close();
                 conn.Dispose();
             }
             return count;
         }
------解决方案--------------------既然用using (SqlConnection conn = new SqlConnection(connString))强制释放资源
 为什么下面还:
conn.Close();
 conn.Dispose(); 
     纠结  不会用就不要用
------解决方案--------------------C#中using关键字的3中用法
一、导入命名空间
using System;
二、强制释放资源
           SqlConnection conn = new SqlConnection(ConnStr);
           conn.Open();
           SqlCommand cmd = new SqlCommand(sql, conn);
           cmd.ExecuteNonQuery();
           conn.Close();
           conn.Dispose();
           以上代码的等同写法:
           using (SqlConnection conn = new SqlConnection(ConnStr))
           {
               conn.Open();
               SqlCommand cmd = new SqlCommand(sql, conn);
               cmd.ExecuteNonQuery();
           }
三、定义别名(命名空间别名、类别名)
using System;
using System.Data.SqlClient;
using colAlias = System.Collections;
namespace System
{
   using cout = System.Console;
   class TestClass
   {
       static void Main()
       {
           colAlias::Hashtable test = new colAlias::Hashtable();
           cout.WriteLine("hello");
       }
   }  
  知道了吧??
    三种用法给你列出来了 自己看下吧
------解决方案--------------------求科目成绩总和有什么意义?
一场考试语文大家考了13243分?
一般算每个人的总分吧。group by userid下。