Cannot implicitly convert type 'System.Collections.Generic.List<string>'
to 'System.Collections.Generic.List<Parts>'
以下是生成此错误的代码。我很确定我在做一些愚蠢的事情。
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;
}
}
错误一直指向这一行:
return lst;
谢谢