1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
MySQLClass db;
private void button1_Click(object sender, EventArgs e)
{
MySqlException err = null;
db = new MySQLClass("Data Source=localhost" +
";Port=3306" +
";Initial Catalog=x" +
";User ID=x" +
";Password=x", out err);
if (err != null)
{
MessageBox.Show("error");
return;
}
List<Teams> source = db.GetDATATABLE("select * from x").Rows.Cast<DataRow>().Select<DataRow, Teams>(delegate(DataRow dr)
{
Teams rec = new Teams
{
id = int.Parse(dr["id"].ToString()),
date_rec = DateTime.Parse(dr["date_rec"].ToString()),
champion = dr["champion"].ToString(),
team1 = dr["team1"].ToString(),
team1_points = dr["team1_points"].ToString(),
team2 = dr["team2"].ToString(),
team2_points = dr["team2_points"].ToString()
};
rec.before2000 = (rec.date_rec.Year < 2000);
return rec;
}
).ToList<Teams>();
Console.Write(source.Count);
}
private class Teams
{
public int id { get; set; }
public DateTime date_rec { get; set; }
public string champion { get; set; }
public string team1 { get; set; }
public string team1_points { get; set; }
public string team2 { get; set; }
public string team2_points { get; set; }
public bool before2000 { get; set; }
}
origin - https://www.pipiscrew.com/?p=18539 table-to-list