Simple linq2sql query to display in crystal report

我们两清 提交于 2019-12-25 08:13:43

问题


I am new to crystal reports and would like to to display sql data on a crystal report using linq2sql. So far i am just trying to display one field (tripNo) with no luck. My error is the data source object is invalid. Here is my code.

private void runstuff()
    {
        using (DataClasses1DataContext db = new DataClasses1DataContext())
        {
            var test = (from s in db.trips
                        select s.tripNo).First();

            CrystalReport1 cr1 = new CrystalReport1();
            cr1.SetDataSource(test);
            crystalReportViewer1.ReportSource = cr1;
        }
    }

回答1:


It's been quite a while since I've used Crystal. However, the problem seems to be the type of 'test'. Crystal probably doesn't know what to do with this. You might want to try this. Note, I've removed the First() method so that a list of rows are returned and then I convert this to a List of entities. Crystal should be able to handle this.

var test = (from s in db.trips
            select s.tripNo).ToList();

            CrystalReport1 cr1 = new CrystalReport1();
            cr1.SetDataSource(test);

Hope this helps.




回答2:


The app.config file needed this line

<startup useLegacyV2RuntimeActivationPolicy="true">


来源:https://stackoverflow.com/questions/10368761/simple-linq2sql-query-to-display-in-crystal-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!