首页 > 代码库 > 日进学习笔记

日进学习笔记

     进入日进的第一周,主要是做winform相关的内容,这次权当复习下,下面做一下这一周的笔记。

1. Combobox关联数据源DataTable

a. 自定义DataTable内容

var dataTable = new DataTable(){};
dataTable.Columns.Add("IdCard", typeof (String));
dataTable.Columns.Add("Name", typeof (String));
var row = dataTable.NewRow();
row["IdCard"] = "123";
row["Name"] = "Lacus";
dataTable.Rows.Add(row);
dataTable.Rows.InsertAt(dataTable.NewRow(),0);

this.comboboxPeople.DataSource = dataTable;
this.comboboxPeople.DisplayMember = "Name";
this.comboboxPeople.ValueMeber = "IdCard";

b. 通过Adapter

var dataTable=new DataTable();

var adapter=new DataAdapter();

adapter.SelectCommand=sqlCommand;

adapter.Fill(dataTable);