不实现接口成员 - C#机房重构

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hdy14/article/details/82192766

前言

在注册窗体中,遇到了这样问题。

解决方案

一、只要继承了接口,就必须全部全写interface中的成员函数

例如interface中有两个

namespace IDAL
{
    public interface RegisterIDAL
    {
        DataTable selectStudent(Entity.Student_Info studentinfo);
        DataTable selectCardNo(Entity.Card_Info cardinfo);

    }
}

继承接口的类中必须写两个:学生表和卡表

public DataTable selectStudent(Entity.Student_Info studentinfo)//查找学生表
        {

            DAL.LoginSQLHelper sqlhelper = new DAL.LoginSQLHelper();//实例化helper层
            //DAL.RegisterDAL sqlhelper = new DAL.RegisterDAL();
            SqlParameter[] sqlParams = { new SqlParameter("@stuNo", studentinfo.stuNo) };//new SqlParameter("@stuName", studentinfo.stuName); }//传参
            string sql = "SELECT *FROM [Student_Info] WHERE stuNo = @stuNo ";//查询语句
            DataTable table = sqlhelper.ExecuteQuery(sql, sqlParams, CommandType.Text);
            return table;

        }
        /// <summary>
        /// 查找卡表
        /// </summary>
        /// <param name="cardinfo"></param>
        /// <returns></returns>
        public DataTable selectCardNo(Entity.Card_Info cardinfo)//查找卡表
        {
            DAL.LoginSQLHelper sqlhelper = new DAL.LoginSQLHelper();//实例化helper层
            SqlParameter[] sqlParams = { new SqlParameter("@CardNo", cardinfo.CardNo) };
            string sql = "SELECT *FROM[Card_Info] WHERE CardNo = @CardNo ";//查询语句
            DataTable table = sqlhelper.ExecuteQuery(sql, sqlParams, CommandType.Text);
            return table;
        }

二、在 报错的那句话上面点右键,选择实现接口。

三、还有就是代码里边缺少public

四、我的代码出现这个问题是因为,D层跟接口层不一致,接口层写的是DataTable selectCardNO,而D层写的是DataTable selectCard,就少了几个字母,继承接口层就要跟接口层一直。

猜你喜欢

转载自blog.csdn.net/hdy14/article/details/82192766