无法将类型'AspPractise.ServiceEvent.EventDetails'隐式转换为'System.Collection.Generic.List< AspPractice' [英] Cannot Implicitly convert type 'AspPractise.ServiceEvent.EventDetails' to 'System.Collection.Generic.List<AspPractice'

查看:46
本文介绍了无法将类型'AspPractise.ServiceEvent.EventDetails'隐式转换为'System.Collection.Generic.List< AspPractice'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ServiceEvent的Web服务,它是一个类的列表,EventDetails但是当我试图在另一个列表中分配值return Bye时,我得到错误为无法隐式转换类型'AspPractise.ServiceEvent.EventDetails'到'System.Collection.Generic.List< asppractice'。>

WebService中的函数

I have a webservice called ServiceEvent which list of a class, EventDetails but when i tried to assign the value return bye the service in the other list I get the error as "Cannot Implicitly convert type 'AspPractise.ServiceEvent.EventDetails'" to 'System.Collection.Generic.List<asppractice'.>
Function in a WebService

public List<EventDetails> GetEventDetails()
      {
          List<EventDetails> lstEvents = new List<EventDetails>();
          SqlConnection conn = new SqlConnection("Data Source=.; Database=Practice; Integrated Security=true;");
          string query = "select * from EventDetails";
          SqlDataAdapter da = new SqlDataAdapter(query, conn);
          try
          {
              conn.Open();
              DataSet ds = new DataSet();
              da.Fill(ds);
              DataTable dt = ds.Tables[0];

              List<DataRow> list = new List<DataRow>(dt.Select());


              var myEnumerable = dt.AsEnumerable();

              lstEvents = (from item in myEnumerable
                           select new EventDetails
                           {
                               Date = item.Field<DateTime>("Date"),
                               Title = item.Field<string>("Title"),
                               PostedBy = item.Field<string>("PostedBy"),
                               Category = item.Field<string>("Category"),
                               Discription = item.Field<string>("Discription")
                           }).ToList();

              conn.Close();
              return lstEvents;

          }
          catch (Exception ex)
          {

              throw ex;
          }
      }





这是我试图实施的:



this is ho i tried to implement:

protected void Page_Load(object sender, EventArgs e)
        {
            ServiceEvent.CrudWebServiceSoapClient service = new                   ServiceEvent.CrudWebServiceSoapClient();
            List<EventDetails> lstEvents;
            lstEvents= service.GetEventDetails();
        }

推荐答案

这篇关于无法将类型'AspPractise.ServiceEvent.EventDetails'隐式转换为'System.Collection.Generic.List&lt; AspPractice'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆