【发布时间】:2016-01-21 15:29:29
【问题描述】:
我是 linq 的新手,并试图理解它。我正在尝试通过 linq 填充数据表,但在 sql 命令适配器中出现错误。 下面是我正在使用的代码,不知道我用对了没有!
这是我得到的错误:
错误 7 无法隐式转换类型 'System.Linq.IQueryable' 到 MySql.Data.MySqlClient.MySqlCommand'
{
northwindEntities1 nw = new northwindEntities1();
var query = from c in nw.customers
join o in nw.orders on c.CustomerID equals o.CustomerID // first join
join od in nw.orderdetails on o.OrderID equals od.OrderID // second join
join p in nw.products on od.ProductID equals p.ProductID // third join
where c.ContactName.StartsWith("Maria Anders")
select new {
o.CustomerID,
c.ContactName,
o.OrderID,
p.ProductID,
p.ProductName,
od.Quantity,
p.UnitPrice
};
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = query;
DataTable datatable = new DataTable();
da.Fill(datatable); // getting value according to imageID and fill dataset
ReportDocument crystalReport = new ReportDocument(); // creating object of crystal report
crystalReport.Load(Server.MapPath("~/custreport.rpt")); // path of report
crystalReport.SetDataSource(datatable); // binding datatable
CrystalReportViewer1.ReportSource = crystalReport;
crystalReport.ExportToHttpResponse
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "PersonDetails");
}
【问题讨论】:
-
您可以简单地使用
query.ToList()作为报告的数据源。
标签: c# mysql linq crystal-reports