我有一个清单:
public class Person
{
public decimal n1 { get; set; }
public decimal n2 { get; set; }
}
List<Person> dbItems = new List<Person>();
public void getinfo(int id)
{
using (var con = new SqlConnection(connectionString))
{
con.Open();
string query = "select * from Zboruri where cod_decol_ateriz = " + id;
var resQuery = new List<Person>();
using (var com = new SqlCommand(query, con))
{
var reader = com.ExecuteReader();
int a = reader.GetOrdinal("number1");
int b = reader.GetOrdinal("number2");
while (reader.Read())
{
resQuery.Add(new Person {
n1 = reader.GetDecimal(a),
n2 = reader.GetDecimal(b)
});
}
}
}
我希望在列表视图中显示此列表,但我不知道如何。我知道我必须使用foreach
,但是如何使用?请给我一个例子如何!