我无法使用下面的数据源将GridView绑定到DataRowView,但是如果我使用通配符,它确实可以工作。?
这个失败: 错误:DataBinding:'System.Data.DataRowView'不包含名为'EnrollmentsTbl.AutoNum'的属性
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataKeyNames="EnrollmentsTbl.AutoNum"
DataSourceID="AccessDataSource1" ForeColor="Black" GridLines="Vertical" PageSize="100">
<PagerSettings Mode="NumericFirstLast" PageButtonCount="75" />
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="EnrollmentsTbl.AutoNum" HeaderText="AutoNum" InsertVisible="False" ReadOnly="True" SortExpression="EnrollmentsTbl.AutoNum" />
<asp:BoundField DataField="SubmitTime" HeaderText="SubmitTime" SortExpression="SubmitTime" />
<asp:BoundField DataField="ClassName" HeaderText="ClassName" SortExpression="ClassName" />
<asp:BoundField DataField="ClassDate" HeaderText="ClassDate" SortExpression="ClassDate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False"/>
<asp:BoundField DataField="DateCompleted" HeaderText="DateCompleted" SortExpression="DateCompleted" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False"/>
<asp:CheckBoxField DataField="Completed" HeaderText="Completed" SortExpression="Completed" />
<asp:BoundField DataField="EnrollmentsTbl.UID" HeaderText="UID" ReadOnly="True" SortExpression="EnrollmentsTbl.UID" />
</Columns>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#6699CC" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:AccessSubSiteString %>"
DeleteCommand="DELETE FROM [EnrollmentsTbl] WHERE [EnrollmentsTbl.AutoNum] = ?"
SelectCommand="SELECT EnrollmentsTbl.AutoNum, EnrollmentsTbl.SubmitTime, EnrollmentsTbl.ClassName,
EnrollmentsTbl.ClassDate, EnrollmentsTbl.DateCompleted, EnrollmentsTbl.Completed, EnrollmentsTbl.UID
FROM [EnrollmentsTbl] INNER JOIN [UsersDataTbl] ON EnrollmentsTbl.UID = UsersDataTbl.UID
WHERE ([EnrollmentsTbl.AutoNum] > ?)"
UpdateCommand="UPDATE [EnrollmentsTbl] SET [UserName] = ?, [SubmitTime] = ?, [ClassName] = ?, [ClassDate] = ?,
[ClassTime] = ?, [Enrolled] = ?, [WaitListed] = ?, [Instructor] = ?, [DateCompleted] = ?, [Completed] = ?, [Walkin] = ?
WHERE [EnrollmentsTbl.AutoNum] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserNameTB" DefaultValue="" Name="?" PropertyName="Text" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="SubmitTime" Type="DateTime" />
<asp:Parameter Name="ClassName" Type="String" />
<asp:Parameter Name="ClassDate" Type="DateTime" />
<asp:Parameter Name="ClassTime" Type="String" />
<asp:Parameter Name="Enrolled" Type="Boolean" />
<asp:Parameter Name="WaitListed" Type="Boolean" />
<asp:Parameter Name="Instructor" Type="String" />
<asp:Parameter Name="DateCompleted" Type="DateTime" />
<asp:Parameter Name="Completed" Type="Boolean" />
<asp:Parameter Name="Walkin" Type="Boolean" />
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
然而:
更改SELECTCOMMAND="SELECT * FROM...
是否可以使用?
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:AccessSubSiteString %>"
DeleteCommand="DELETE FROM [EnrollmentsTbl] WHERE [EnrollmentsTbl.AutoNum] = ?"
SelectCommand="SELECT *
FROM [EnrollmentsTbl] INNER JOIN [UsersDataTbl] ON EnrollmentsTbl.UID = UsersDataTbl.UID
WHERE ([EnrollmentsTbl.AutoNum] > ?)"
UpdateCommand="UPDATE [EnrollmentsTbl] SET [UserName] = ?, [SubmitTime] = ?, [ClassName] = ?, [ClassDate] = ?,
[ClassTime] = ?, [Enrolled] = ?, [WaitListed] = ?, [Instructor] = ?, [DateCompleted] = ?, [Completed] = ?, [Walkin] = ?
WHERE [EnrollmentsTbl.AutoNum] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserNameTB" DefaultValue="" Name="?" PropertyName="Text" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="SubmitTime" Type="DateTime" />
<asp:Parameter Name="ClassName" Type="String" />
<asp:Parameter Name="ClassDate" Type="DateTime" />
<asp:Parameter Name="ClassTime" Type="String" />
<asp:Parameter Name="Enrolled" Type="Boolean" />
<asp:Parameter Name="WaitListed" Type="Boolean" />
<asp:Parameter Name="Instructor" Type="String" />
<asp:Parameter Name="DateCompleted" Type="DateTime" />
<asp:Parameter Name="Completed" Type="Boolean" />
<asp:Parameter Name="Walkin" Type="Boolean" />
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
我需要在gridview中使用bith tabes中的字段,因此通配符不起作用。
答案 0 :(得分:0)
没有提供任何帮助,但似乎我找到了解决方案/工作方式:
部分问题是,当在SELECT语句(SelectCommand)
中使用通配符(*)时,INNER JOIN
返回的字段是混合的,有些具有table.column而其他字段只有列。示例:如果两个表都包含AutoNum
,则返回table1.AutoNum和table2.AutNum - 但如果只有一个表有一个字段,则仅返回Field
- 这是设置列的问题gridview中导致我问题的名称。