DAL C#错误'无法隐式转换类型' [英] DAL C# error 'cannot implicitly convert type'
本文介绍了DAL C#错误'无法隐式转换类型'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public 列表< BOL.MonthlyEvent>列表(字符串 subsidiary_cd,字符串 costcenter)
{
oConnection.ConnectionString = ConnectionString ;
oConnection.Open();
BOL.MonthlyEvent MEvent = new BOL.MonthlyEvent();
SqlCommand oCommand = new SqlCommand();
oCommand.Connection = oConnection;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandText = Monthly_Event_LIST1;
oCommand.Parameters.Add( new SqlParameter( @SUBS_CD,subsidiary_cd));
oCommand.Parameters.Add( new SqlParameter( @CostCenter,costcenter));
SqlDataReader oReader = oCommand.ExecuteReader();
while (oReader.Read())
{
if (oReader [ Event_Date]。ToString()== ){Event.EventDate = null ; } else {MEvent.EventDate = Convert.ToDateTime(oReader [ EVENT_DATE跨度>]的ToString()); }
MEvent.EventTitle = oReader.IsDBNull(oReader.GetOrdinal( EventTitle)) ? :oReader [ EVENTTITLE跨度>]的ToString();
MEvent.EventDescription = oReader.IsDBNull(oReader.GetOrdinal( Event_Description))? :oReader [ EVENT_DESCRIPTION跨度>]的ToString();
}
oReader.Close();
oConnection.Close();
return MEvent;
}
错误:
无法隐式转换类型' BOL.MonthlyEvent' to ' system.collections.generic.list< BOL.MonthlyEvent>'
我是什么尝试过:
无法将类型隐式转换为system.collections.generic.list
解决方案
< blockquote>您的方法名称是List
与System.Collections.Generic.List冲突
。
解决方案是: -
更改方法名称列表
到任何不引用预定义关键字或类名的东西....
public List<BOL.MonthlyEvent> List(string subsidiary_cd,string costcenter)
{
oConnection.ConnectionString = ConnectionString;
oConnection.Open();
BOL.MonthlyEvent MEvent = new BOL.MonthlyEvent();
SqlCommand oCommand = new SqlCommand();
oCommand.Connection = oConnection;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandText = "Monthly_Event_LIST1";
oCommand.Parameters.Add(new SqlParameter("@SUBS_CD", subsidiary_cd));
oCommand.Parameters.Add(new SqlParameter("@CostCenter", costcenter));
SqlDataReader oReader = oCommand.ExecuteReader();
while (oReader.Read())
{
if (oReader["Event_Date"].ToString() == "") { Event.EventDate = null; } else { MEvent.EventDate = Convert.ToDateTime(oReader["Event_Date"].ToString()); }
MEvent.EventTitle = oReader.IsDBNull(oReader.GetOrdinal("EventTitle")) ? "" : oReader["EventTitle"].ToString();
MEvent.EventDescription = oReader.IsDBNull(oReader.GetOrdinal("Event_Description")) ? "" : oReader["Event_Description"].ToString();
}
oReader.Close();
oConnection.Close();
return MEvent;
}
error :
cannot implicitly convert type'BOL.MonthlyEvent' to 'system.collections.generic.list<BOL.MonthlyEvent>'
What I have tried:
cannot implicitly convert type to system.collections.generic.list
解决方案
Your Method name is"List"
which conflict with"System.Collections.Generic.List"
.
Solution is:-
Change the method nameList
to any thing which doesn't refer to Predefined keyword or class name....
这篇关于DAL C#错误'无法隐式转换类型'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文