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
The return type of method GetParts() is
List<Parts>, but in function, you try to return aList<string>try this: