c# – DataTable上的LINQ查询 – 找不到查询模式的实现

c# – DataTable上的LINQ查询 – 找不到查询模式的实现,第1张

概述任何人都可以告诉我为什么这不编译?错误是: Could not find an implementation of the query pattern for source type System.Data.DataTable. Where not found. using System;using System.Collections.Generic;using System.Linq;u 任何人都可以告诉我为什么这不编译?错误是:

Could not find an implementation of the query pattern for source type System.Data.Datatable. Where not 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查询 – 找不到查询模式的实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1222221.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存