I have:
<asp:GridView ID="ClassesGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="CourseNumber" DataSourceID="AccessClasses"
AutoGenerateEditButton="True" >
<Columns>
<asp:BoundField DataField="CourseNumber" HeaderText="CourseNumber" ReadOnly="True" SortExpression="CourseNumber" />
<asp:BoundField DataField="Teacher1" HeaderText="Teacher1" SortExpression="Teacher1" />
<asp:BoundField DataField="T1PhoneNumber" HeaderText="T1PhoneNumber" SortExpression="T1PhoneNumber" />
<asp:BoundField DataField="T1Email" HeaderText="T1Email" SortExpression="T1Email" />
<asp:BoundField DataField="Teacher2" HeaderText="Teacher2" SortExpression="Teacher2" />
<asp:BoundField DataField="T2PhoneNumber" HeaderText="T2PhoneNumber" SortExpression="T2PhoneNumber" />
<asp:BoundField DataField="T2Email" HeaderText="T2Email" SortExpression="T2Email" />
<asp:BoundField DataField="OrderToVisit" HeaderText="OrderToVisit" SortExpression="OrderToVisit" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessClasses" runat="server" DataFile="~/App_Data/SundaySchool.mdb"
SelectCommand="SELECT [CourseNumber], [Teacher1], [T1PhoneNumber], [T1Email], [Teacher2], [T2PhoneNumber], [T2Email], [OrderToVisit] FROM [Classes]"
UpdateCommand="UPDATE Classes SET Teacher1 = @Teacher1 WHERE CourseNumber = @CourseNumber">
</asp:AccessDataSource>
For the life of me I can't figure out why this won't update. The 'Edit' record works, but after changing the record and hitting 'Update' nothing happens. Everything reverts back.
EDIT: Something weird is happening here. If I set a value in the 'Teacher2' column, that will then populate to the 'Teacher1' column. The CourseNumber column also isn't what it should be which is why WHERE CourseNumber = @CourseNumber is not working.
You have to change the UpdateCommand, notice ?
instead of @
:
<asp:AccessDataSource ID="AccessClasses" runat="server" DataFile="~/App_Data/SundaySchool.mdb"
SelectCommand="SELECT [CourseNumber], [Teacher1], [T1PhoneNumber], [T1Email], [Teacher2], [T2PhoneNumber], [T2Email], [OrderToVisit] FROM [Classes]"
UpdateCommand="UPDATE Classes SET Teacher1 = ? WHERE CourseNumber = @CourseNumber">
</asp:AccessDataSource>
Here's more info about AccessDataSource: MSDN .
I figured this out. The UpdateCommand MUST follow the SelectCommand exactly with exception to the Primary Key, CourseNumber. EVERYTHING in the select must be in the update in the correct. Once I did that, everything worked great!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.