构造DataTable

手动构造一个DataTable:

 1                 DataTable dt = new DataTable();
 2                 dt.Columns.Add("ID", typeof(string));
 3                 dt.Columns.Add("Name", typeof(string));
 4                 DataRow _Row1 = dt.NewRow();
 5                 _Row1["ID"] = "1";
 6                 _Row1["Name"] = "";
 7                 dt.Rows.Add(_Row1);
 8                 DataRow _Row2 = dt.NewRow();
 9                 _Row2["ID"] = "0";
10                 _Row2["Name"] = "";
11                 dt.Rows.Add(_Row2);
12                 comboBox1.DisplayMember = "Name";
13                 comboBox1.ValueMember = "ID";
14                 comboBox1.DataSource = dt;

 

posted @ 2014-01-08 21:51  F_wes  阅读(421)  评论(0编辑  收藏  举报