I'm trying to update an access database when using a Grid View in Visual Studio 2010 but not having any success. Let me try and explain what I have.
I have an access database with a table "tblConfirmedworkhours" which has fields "dateworked" & "confirmed". I can display the filtered table on my webpage with the edit/update links but the table won't update.
Option 1: I would like (if possible) is to not have to click on the edit & update buttons, just edit the data on the screen (I'm thinking of some kind of similar thing to a continuous form is MS Access and then hit some kind of save button (which (again if possible) would run an append query already created and stored in my access database "qryToHistory".
Option 2: Be able to use the edit/update buttons to change the data in the table.
Here is my current code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" Width="983px"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
<Columns>
<asp:BoundField DataField="WorkHourID" Visible="false"
HeaderText="Timesheet ID" />
<asp:BoundField DataField="EmpName" HeaderText="Employee"
SortExpression="EmpName" />
<asp:BoundField DataField="dateworked"
HeaderText="Date" SortExpression="dateworked" ApplyFormatInEditMode="True">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:CheckBoxField DataField="confirmed" HeaderText="Confirmed"
SortExpression="confirmed" Text="This is OK">
<ItemStyle HorizontalAlign="Center" />
</asp:CheckBoxField>
</Columns>
<EditRowStyle Width="500px" Wrap="True" />
<EmptyDataRowStyle Width="5000px" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/PayrollDirect.accdb"
SelectCommand="SELECT [WorkHourID], [EmpName], [dateworked], [confirmed] FROM [tblConfirmedworkhours] WHERE (([CompanyID] = ?) AND ([confirmed] = ?)) ORDER BY [dateworked]"
UpdateCommand="UPDATE tblConfirmedworkhours SET dateworked=dateworked, confirmed=confirmed where WorkHourID=WorkHourID">
<SelectParameters>
<asp:SessionParameter DefaultValue="0" Name="CompanyID" SessionField="UserID" Type="Int32" />
<asp:Parameter DefaultValue="false" Name="confirmed" Type="Boolean" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="dateworked"/>
<asp:Parameter Name="confirmed"/>
</UpdateParameters>
</asp:AccessDataSource>
Is Option 1 a possibility, if so how.
If option 1 is not possible, how can I sort the problem of updating my table as in option 2.
I'm still learning Visual Studio so any and all help is gratefully appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…