public class Class1
{
public Class1(int id , string name , string cast)
{
this.id = id;
this.name = name;
this.cast = cast;
}
public int id { get; set; }
public string name { get; set; }
public string cast { get; set; }
}
public List<Class1> getall() {
List<Class1> list = new List<Class1>();
using (SqlConnection con = Main.Maindata2()){
SqlCommand cmd
= new SqlCommand("SELECT * FROM List", con);
con.Open();
SqlDataReader reaader = cmd.ExecuteReader();
while (reaader.Read()) {
// list.Add((int)reaader["Id"],(string)reaader["name"],(string)reaader["cast"]);
//list.CLAS
list.Add((int)reaader["Id"], (string)reaader["name"], (string)reaader["cast"]);
}
return list;
}
}
}
答案 0 :(得分:1)
你需要在while循环中执行此操作
var obj = new Class1((int)reaader["Id"].ToString(), reaader["name"].ToString(), reaader["cast"].ToString());
list.Add(obj);