SQL 文は使えません。代わりに LINQ to DataSet を使います。
C#
1// DataTable の作成
2var table = new DataTable();
3table.Columns.AddRange(new DataColumn[] {
4 new DataColumn("No", typeof(int)),
5 new DataColumn("LastName", typeof(string)),
6 new DataColumn("MothersLastName", typeof(string)),
7 new DataColumn("BirthPlace", typeof(string)),
8 new DataColumn("MothersBirthPlace", typeof(string)),
9});
10table.Rows.Add(1, "松本", "松本", "兵庫", "兵庫");
11table.Rows.Add(2, "浜田", "浜田", "大阪", "大阪");
12table.Rows.Add(3, "東野", "今田", "奈良", "滋賀");
13
14// LINQ 式
15var results =
16 from row in table.AsEnumerable()
17 select new {
18 No = row.Field<int>("No"),
19 Count = row.Field<string>("LastName") == row.Field<string>("MothersLastName")
20 && row.Field<string>("BirthPlace") == row.Field<string>("MothersBirthPlace")
21 ? 1
22 : 0
23 };
24
25// 出力
26foreach (var result in results) Console.WriteLine(result);
LINQ 式にはもう一つ書き方があります。上記の書き方は下記のサブセットでしかありません。
今回は必要ありませんが、機能をフルに使いたい時には次のように書きます。
C#
1results = table
2 .AsEnumerable()
3 .Select(row => new
4 {
5 No = row.Field<int>("No"),
6 Count = row.Field<string>("LastName") == row.Field<string>("MothersLastName")
7 && row.Field<string>("BirthPlace") == row.Field<string>("MothersBirthPlace")
8 ? 1
9 : 0
10 });
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。