0

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;
        }
    }
4

2 回答 2

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.

于 2012-04-29T00:40:23.227 回答
0

The app.config file needed this line

<startup useLegacyV2RuntimeActivationPolicy="true">
于 2012-05-02T05:17:54.693 回答