이 쿼리를 작성합니다.그리드에서 linq 쿼리의 데이터 표시 문제
다음 LinqSQl
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
}
into d
group d by d.OrderID;
나는 데이터 그리드에서이 데이터를 표시하고자하는 것은이 내 마크 업입니다 :
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="asp1._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="false"
CellPadding="4" ForeColor="#333333" Width="600px">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="Name" />
<asp:BoundField DataField="CustomerName" HeaderText="CustomerName" />
<asp:BoundField DataField="EmployeeName" HeaderText="EmployeeName" />
<asp:BoundField DataField="ShipperName" HeaderText="ShipperName" />
<asp:BoundField DataField="Products" HeaderText="Products" />
<asp:BoundField DataField="TotalPrice" HeaderText="TotalPrice" />
</Columns>
<HeaderStyle BackColor="#7961da" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
</body>
</html>
따라서 방법
Grid.DataSource = query.ToList();
Grid.DataBind();
그리고 오류가 발생합니다 : 필드 또는 속성 'OrderID'라는 이름이 선택된 데이터 소스에서 발견되지 않았습니다.
내 문제는 무엇입니까?
내가이 쿼리를
var query1 = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
};
Grid.DataSource = query1;
Grid.DataBind();
내가 데이터를 표시하지만 그룹화되지 않습니다 사용할 때 때문이다.
는 나는이 결과를 얻으려면
OrderId| CustomerName| EmployeeName |ShipperName | Products| TotalPrice 1 Apple Kevin AIG Iphone 1000 1 Apple Kevin AIG IPAD 1100 2 Samsung John KMP S6 900 2 Samsung John KMP S5 800
이 데이터를 얻을.
OrderId| CustomerName| EmployeeName |ShipperName | Products | TotalPrice 1 Apple Kevin AIG Iphone,Ipad 2100 2 Samsung John KMP S6,s5 1700
격자보기에 대해이 마크 업을 모두 가지고 있습니까? – Andrei
그 gridview 마크 업으로, 당신이 대답을 찾은 적이 있는지 궁금합니다. 마크 업에서 일부 필드를 정의하는 데주의해야합니까? –
@husnain_sys mu 전체 마크 업이 있습니다 – user4523894