这下面的代码示例从MSDN借这里.我没有在我的代码中获得query.CopyToDataTable().(请参阅以下代码中的注释行).
public static bool SetPhysicianAsNotonServer(DataTable dt)
        {
            DataTable dtPhysicianServer = dt;
            DataTable dtPhysicianClient = GetPhysicianClient();
            var query =
                from SPhysician in dtPhysicianServer.AsEnumerable()
                join CPhysician in dtPhysicianClient.AsEnumerable()
                on SPhysician.Field<string>("PhysicianNumber") equals
                    CPhysician.Field<string>("PhysicianNumber")
                select new
                {
                    PhysicianNumber = CPhysician.Field<string>("PhysicianNumber")
                 };
            DataTable FilterDt = query; //query.CopyToDataTable();
            //YET TO DO CODE HERE
            return true;
        }
Rex*_*x M 21
您的select语句返回一系列字符串(IEnumerable<string>或IQueryable<string>),而不是一系列DataRows.CopyToDataTable()仅适用于IEnumerable<T>T或从DataRow派生的位置.
而不是select new { ... }- 只会让你获得该类型的新序列,请尝试:
select CPhysician;
哪个应该返回所需的CPhysician行序列.
编辑 如果您希望将非数据表派生的T转换为数据表,MSDN有一个反映任何类型并执行转换的示例类.
http://msdn.microsoft.com/en-us/library/bb669096.aspx
它存在于特定的命名空间中,您导入它吗?
System.Data.DataTableExtensions.CopyToDataTable() 
同时确认添加此参考
System.Data.DataSetExtensions