谁能告诉我为什么这不能编译?错误是:
找不到源类型的查询模式的实现
System.Data.DataTable
。Where
未找到。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace caLINQ
{
class Program
{
static void Main(string[] args)
{
string connectionString = "Data Source=STEVEN-PC\\SQLEXPRESS;Initial Catalog=linqtest;Integrated Security=True;Pooling=False";
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
{
connection.Open();
String cmdText = "select * from customers";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdText, connection);
System.Data.SqlClient.SqlDataReader dr;
dr = cmd.ExecuteReader();
DataSet ds = new DataSet();
ds.Load(dr, LoadOption.OverwriteChanges, "tab1");
DataTable dt = ds.Tables[0];
var qy = from c in dt // error is here
where c.country == "Italy"
select c.name;
}
Console.ReadKey();
}
}
}