【三层架构】请教高手——dgv控件不显示信息
MyShoolUI.rar
(560.62 KB)
附件已经上传,里面有代码有数据库,用Visual Studio 2010 写的代码,就是dgv控件不显示数据,请教高手帮忙,Thank you!!!!!
——————————【表示层】——————————————————————————
private void SearchStudentInfo_Load(object sender, EventArgs e)
{
IStudentInfoManagerBll info = new StudentInfoManager();
List<Student> sList = info.SearchStudentInfo();
this.dgvDisplayStudent.DataSource = new BindingList<Student>(sList);
}
}
——————————【业务逻辑层】——————————————————————————
namespace MySchoolBll
{
public interface IStudentInfoManagerBll
{
List<Student> SearchStudentInfo();//查询全部学生
}
}
——————————————————————————————————————————
namespace MySchoolBll.Interfacebll
{
public class StudentInfoManager:IStudentInfoManagerBll
{
StudentInfoService ss = new StudentInfoService();
public List<Student> SearchStudentInfo()
{
return ss.SearchStudentInfo();
}
}
}
——————————【数据访问层】——————————————————————————
namespace MySchoolDAL
{
public class StudentInfoService
{
public List<Student> SearchStudentInfo()
{
List<Student> sList = new List<Student>();
string sql = string.Format("select * from [Student]");
using (SqlConnection conn=new SqlConnection(DBHelper.connString))
{
try
{
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
using (SqlDataReader dr = comm.ExecuteReader())
{
while (dr.Read())
{
Student stu = new Student();
stu.StudentID = Convert.ToInt32(dr["StudentID"]);
stu.StudentName = dr["StudentName"].ToString();
stu.StudentAddress = dr["StudentAddress"].ToString();
stu.Phone = dr["Phone"].ToString();
sList.Add(stu);
}
}
}
catch (Exception ex)
{
throw ex;
}
return sList;
}
}
}
}
————————————————————————
namespace MySchoolDAL
{
class DBHelper
{
public static readonly string connString = ConfigurationManager.ConnectionStrings["MySchoolConnectionString"].ToString();
}
}
——————————【实体类】——————————————————————————
namespace MySchoolModles
{
public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public string StudentAddress { get; set; }
public string Phone { get; set; }
}
}