Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8269677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:18:32+00:00 2026-06-08T06:18:32+00:00

Cannot implicitly convert type ‘System.Collections.Generic.List<string>’ to ‘System.Collections.Generic.List<Parts>’ Below is the code generating this error.

  • 0
Cannot implicitly convert type 'System.Collections.Generic.List<string>'
to 'System.Collections.Generic.List<Parts>'

Below is the code generating this error. I am pretty sure I am doing something silly.

public class Parts
{


public string computername { get; set; }


public List<Parts> GetParts()
{
    List<string> lst = new List<string>(); 
   //The object that will physically connect to the database 
   using(SqlConnection cnx = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["request"].ConnectionString))  
   { 
            //The SQL you want to execute 
       SqlCommand cmd = new SqlCommand("SELECT * FROM REQUESTS", cnx); 
           //Open the connection to the database 
           cnx.Open(); 
           //execute your command 
           SqlDataReader dataReader = cmd.ExecuteReader(); 
           { 
             //Loop through your results 
             while(dataReader.Read()) 
             { 
                lst.Add(Convert.ToString(dataReader["titlename"])); 
             } 
           } 
   } 
   return lst; 
} 

}

The error keeps pointing to this line:

   return lst; 

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:18:35+00:00Added an answer on June 8, 2026 at 6:18 am

    The return type of method GetParts() is List<Parts>, but in function, you try to return a List<string>

    try this:

    public List<Parts> GetParts()
    {
        List<Parts> lst = new List<Parts>(); 
        using (SqlConnection cnx = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["request"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM REQUESTS", cnx);
            cnx.Open();
            Parts parts = null; 
            SqlDataReader dataReader = cmd.ExecuteReader();
            { 
                while (dataReader.Read())
                {
                    parts = new Parts();
                    parts.computername = dataReader["titlename"].ToString();
                    lst.Add(parts);
                }
            }
        }
        return lst;
    } 
    
    public void SomeMethod(List<Parts> parts)
    {
        List<string> title = new List<string>();
        foreach(var item in parts)
        {
            title.Add(item.titlename);
        }
        this.ddlPartsTitle.Datasource = title;
        this.ddlPartsTitle.DataBind();
    }
    
    public YourClassName()
    {
        this.SomeMethod(this.GetParts());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Error Cannot implicitly convert type 'string[]' to 'System.Collections.Generic.List<string>' The above error is caused when
The following code produces the issue Cannot implicitly convert type 'System.Collections.Generic.IEnumberable<DataField<string>>' to 'DataFields'. An
I am getting this error. Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<ModelBase.IModel>' to 'System.Collections.Generic.List<ModelBase.User>'
I am getting the following error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'. An
Why do I get this error message: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'
I'm receiving this error in my Linq statement --- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable'
I am receiving the following error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'Munchkin.Model.PlayerProfiles.Profile'. An
I am getting an error Error 826 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'OVR.Models.ChildInfoModel'.
Error 4 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<CCE_2009.Data.Person>>' to 'System.Collections.Generic.IEnumerable<CCE_2009.Data.Person>' Generated from: var RecoveryManagerQuery =
I'm receiving the following error : Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>>' to 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>'. An

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.