急!!!!请大家帮我解决这个问题
我定义了一个Leaveword类继承了ILeaveword接口但出现了以编译时出现了下面错误:编译器错误信息: CS0266: 无法将类型“Leaveword”隐式转换为“ILeaveword”。存在一个显式转换(是否缺少强制转换?)
源错误:
行 27: private void BindLeavewordData()
行 28: {
行 29: ILeaveword word = new Leaveword();
行 30: SqlDataReader dr = word.GetLeavewords();
行 31: LeavewordList.DataSource = dr;
定义接口:
public inte易做图ce ILeaveword
{
SqlDataReader GetLeavewords();
}
我有实现接口的:
public class Leaveword:ILeaveword
{
private static readonly string GETLEAVEWORDS = "select * from Leavewords";
public SqlDataReader GetLeavewords()
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
SqlCommand myCommand = new SqlCommand(GETLEAVEWORDS,myConnection);
SqlDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex);
}
return dr;
}
--------------------编程问答-------------------- 定义接口:
public inte易做图ce ILeaveword
{
SqlDataReader GetLeavewords();
}
我有实现接口的:
public class Leaveword:ILeaveword
{
private static readonly string GETLEAVEWORDS = "select * from Leavewords";
public SqlDataReader GetLeavewords()
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
SqlCommand myCommand = new SqlCommand(GETLEAVEWORDS,myConnection);
SqlDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex);
}
return dr;
} --------------------编程问答-------------------- Leaveword word = new Leaveword();
或者
ILeaveword word =(ILeaveword) new Leaveword();
--------------------编程问答-------------------- 搂主,我测试你的代码,没有一点问题,看看是不是项目属性里对编译器的设置有问题。还是你的IDE有问题 --------------------编程问答-------------------- 也不行呀!不是说什么编译器错误信息: CS0266: 无法将类型“Leaveword”隐式转换为“ILeaveword”。存在一个显式转换(是否缺少强制转换?) --------------------编程问答-------------------- 是呀1我前天都行呀1 --------------------编程问答-------------------- 保险一点,还是强转换一下把 --------------------编程问答-------------------- --------------------编程问答-------------------- Click the link to solve your problem.Good luck! --------------------编程问答-------------------- 学习学习
补充:.NET技术 , ASP.NET