C# 无法将类型“string”隐式转换为“System.Collections.Generic.List

C# 无法将类型“string”隐式转换为“System.Collections.Generic.List,c#,C#,我的控制器显示错误请解决显示错误无法将列表转换为字符串 public JsonResult GetProperty_id(int selectedValue) { List < string > properties = new List < string > ().ToList(); // Property model1 = new Property(); SqlConnection con = new SqlConnection("Se

我的控制器显示错误请解决显示错误无法将列表转换为字符串

public JsonResult GetProperty_id(int selectedValue) 
{
    List < string > properties = new List < string > ().ToList();
    //    Property model1 = new Property();
    SqlConnection con = new SqlConnection("Server=miracle\\SQLExpress; database=CRUIdb; user id=sa; password=dotnet");
    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT property_id  FROM Service_Property WHERE service_id =" + selectedValue, con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);

    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) 
    {
        properties = (ds.Tables[0].Rows[0]["property_id"]); //error cannot covert
    }
    return Json(properties, JsonRequestBehavior.AllowGet);
}
您正在为列表分配一个字符串值,这是不可能的,您应该将每个值添加到集合中,如下所示

properties.Add(ds.Tables[0].Rows[0]["property_id"]);
表[0]。行[0][property_id]是一个字符串,但您正在尝试将属性设置为该值。属性从其声明中删除


也许您希望执行properties.Addds.Tables[0].Rows[0][property\u id],这将符合这样一个事实,即在您的循环之后,您正在访问它,而即使它当前已编译,它也只从最后一个循环中获取值。

此外,第一行中不需要ToList。Listproperties=newlist.ToList@Jenish Rabadiya你能看看这个问题吗@阿萨尔这条线索不是我发起的。我刚刚编辑了这个问题,以便使它更具可读性。