标题:【三层架构】请教高手——dgv控件不显示信息
取消只看楼主
yineng88
Rank: 1
等 级:新手上路
帖 子:9
专家分:8
注 册:2013-8-20
结帖率:50%
已结贴  问题点数:20 回复次数:2 
【三层架构】请教高手——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; }
    }
}








搜索更多相关主题的帖子: private 数据库 Thank 信息 
2013-08-22 11:28
yineng88
Rank: 1
等 级:新手上路
帖 子:9
专家分:8
注 册:2013-8-20
得分:0 
回复 2楼 Aviva_Wang
谢谢,非常感谢

我是个菜鸟,我就是个菜鸟
2013-08-22 16:13
yineng88
Rank: 1
等 级:新手上路
帖 子:9
专家分:8
注 册:2013-8-20
得分:0 


我是个菜鸟,我就是个菜鸟
2013-08-24 12:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-419506-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.163809 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved