Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
C#
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:
C#
protected void Page_Load(object sender, EventArgs e)
        {
            ServiceEvent.CrudWebServiceSoapClient service = new                   ServiceEvent.CrudWebServiceSoapClient();
            List<EventDetails> lstEvents;
            lstEvents= service.GetEventDetails();
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900