linq将数据表绑定到数据库时出错 [英] error in binding datatable to database by linq

查看:89
本文介绍了linq将数据表绑定到数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i am going to bind a datatable by linq query to database
Below is my query..




DataTable table = new DataTable();
               IEnumerable<double> query = (from st in obj.Book_details
                               select new {st.Category,st.Book_Id,st.Edition,st.Name,st.Price,st.Quantity,st.Quick_overview }).Take(20);
               query.CopyToDataTable(table, LoadOption.PreserveChanges);<pre lang="text">







现在我我在最后一行得到错误我绑定我的表

和错误是没有拳击




now i am getting error in last line where i bind my table
and the error is that there is no boxing

Error	149	The type 'double' cannot be used as type parameter 'T' in the generic type or method 'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>, System.Data.DataTable, System.Data.LoadOption)'. There is no boxing conversion from 'double' to 'System.Data.DataRow'.
Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<double>'. An explicit conversion exists (are you missing a cast?)	

推荐答案

如果返回的除外,则不能使用query.CopyToDataTable()方法DataRow类型。这里是Double。

如果要处理任何其他数据类型,应考虑添加扩展方法



请参阅以下链接,其中显示了在非DataRow类型的情况下处理



http://msdn.microsoft.com/en-us/library/bb669096.aspx [ ^ ]



希望这有助于
You cannot use query.CopyToDataTable() method if it returns other than a DataRow type. Here it is Double.
Should consider adding an extension method if to take care of any other datatypes

Refer the below link which shows how to handle in case of non DataRow type

http://msdn.microsoft.com/en-us/library/bb669096.aspx[^]

Hope this helps


这篇关于linq将数据表绑定到数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆