
Could not find an implementation of the query pattern for source type
System.Data.Datatable.Wherenot found.
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(); } }}解决方法 尝试: var qy = from c in dt.AsEnumerable() where c.FIEld<string>("country") == "Italy" select c.FIEld<string>("name"); AsEnumerable()将返回IEnumerable< DaTarow>可以与liNQ一起使用.
总结以上是内存溢出为你收集整理的c# – DataTable上的LINQ查询 – 找不到查询模式的实现全部内容,希望文章能够帮你解决c# – DataTable上的LINQ查询 – 找不到查询模式的实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)