0

我有一个数据列表,并且正在为“领导”表使用左外连接,我试图在其中获得“职位”。但我收到错误消息,“DataBinding:'System.Data.DataRowView' 不包含名为 'Position' 的属性。”

CustomerTable                                    LeadershipTable
CustomerId   Name,   LeadershipPosition       Id          Position
   1         Bob        1                      1          President
   2         Greg       2                      2          vice-President
   3         Polly      4                      3          Secratary
   4         Anna       3                      4          Treasurer

<asp:DataList ID="DataList1" RepeatColumns="2" DataKeyField="CustomerId" runat="server" DataSourceID="SqlDataSource2">

以及从代码隐藏填充的 sqldatasource:

SqlDataSource2.SelectCommand = "SELECT Customer.CustomerId, Customer.FName + '   ' + Customer.LName As Name, Customer.Address1, Customer.City, Customer.State, Customer.Zip, Customer.Cell, Customer.Email, Customer.profilePic, Customer.LeadershipPosition From Customer LEFT OUTER JOIN Leadership ON Customer.LeadershipPosition = Leadership.Id WHERE Customer.CommitteeId = '1'"
    SqlDataSource2.DataBind()
4

1 回答 1

1

您指定将“LeadershipTable.Position”的别名指定为职位。检查下面的代码

SqlDataSource2.SelectCommand = "SELECT Customer.CustomerId, Customer.FName + '   ' + Customer.LName As Name, Customer.Address1, Customer.City, Customer.State, Customer.Zip, Customer.Cell, Customer.Email, Customer.profilePic, Customer.LeadershipPosition, LeadershipTable.Position Position From Customer LEFT OUTER JOIN Leadership ON Customer.LeadershipPosition = Leadership.Id WHERE Customer.CommitteeId = '1'"
SqlDataSource2.DataBind()
于 2013-10-01T04:05:25.043 回答