當前位置:編程學習大全網 - 網站源碼 - c#中Winform控件的數據源的填充方式,也就是DataSource的類型有幾種?

c#中Winform控件的數據源的填充方式,也就是DataSource的類型有幾種?

有兩種方式,壹種是直接綁定到數據源對象,另壹種是綁定到BindingSource組件,將BindingSource的DataSource屬性設置為壹個列表,第二種方法更常用。

下例查詢SalesOrderHeader表中2001年8月8號以後的序列,使用CopyToDataTable方法從查詢產生DataTable。並綁定到BindingSource。

DataTable?orders?=?ds.Tables["SalesOrderHeader"];

//查詢SalesOrderHeader表中2001年8月以後的訂單

IEnumerable<DataRow>?query?=?from?order?in?orders.AsEnumerable()

where?order.Field<DateTime>("OrderDate")?>?new?DateTime(2001,?8,?1)

select?order;

//用CopyToDataTable方法從查詢生成表

DataTable?boundTable?=?query.CopyToDataTable<DataRow>();

//綁定表作為BindingSource的數據源對象

bindingSource1.DataSource?=?boundTable;

dataGridView1.AutoResizeColumns();

dataGridView1.DataSource?=?bindingSource1;

  • 上一篇:小米官網的手機圖片是js上傳的
  • 下一篇:我想問壹下侍魂墊子強化技巧
  • copyright 2024編程學習大全網