【VB.NET】LINQ友の会【C#, C♯, C#】 at TECH
[2ch|▼Menu]
25:デフォルトの名無しさん
08/02/12 16:13:13
続き(>>24)
private void Test9()
{
// DataContext を使ったバージョン
using (var myDataContext = new System.Data.Linq.DataContext("Data Source=貴方のPC;Initial Catalog=AdventureWorks;Integrated Security=True"))
{
// サンプルデータベースからデータを取り込む
System.Data.Linq.Table<TableLocation> orginalTable = myDataContext.GetTable<TableLocation>();

// LocationIDが10以下の行のみのテーブルを作る
var lessThan10Table = from row in orginalTable where row.LocationID < 10 select row;

// ためしに表示
this.dataGridView1.DataSource = orginalTable;
this.dataGridView2.DataSource = lessThan10Table;

// *** 重要な特徴の紹介 ***
// キャストしなくても使えるのでミスが少なく便利である
foreach (TableLocation tmp in lessThan10Table)
{
System.Console.WriteLine("{0},{1},{2},{3},{4}"
, tmp.LocationID
, tmp.Name
, tmp.CostRate
, tmp.Availability
, tmp.ModifiedDate);
}
}
}



次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

4660日前に更新/117 KB
担当:undef