namespace BusinessLayer
{
public class StudentBusinessLayer
{
public List<Student> getStudents(string storedProcedure)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
{
List<Student> students = new List<Student>();
SqlCommand comm = new SqlCommand(storedProcedure, conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
while (rdr.Read())
{
Student s = new Student();
s.id = Convert.ToInt32(rdr["id"]);
s.Name = rdr["Name"].ToString();
s.TotalMarks = Convert.ToInt32(rdr["TotalMarks"]);
students.Add(s);
}
return students;
}
}
}
}
答案 0 :(得分:2)
您的Student
课程似乎不是public
,请让public
修正您的错误。
答案 1 :(得分:0)
你的回归是错误的:
namespace BusinessLayer
{
public class StudentBusinessLayer
{
public List<Student> getStudents(string storedProcedure)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
{
List<Student> students = new List<Student>();
SqlCommand comm = new SqlCommand(storedProcedure, conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
while (rdr.Read())
{
Student s = new Student();
s.id = Convert.ToInt32(rdr["id"]);
s.Name = rdr["Name"].ToString();
s.TotalMarks = Convert.ToInt32(rdr["TotalMarks"]);
students.Add(s);
}
}
return students;
}
}
}