SELECT works, Edit button works, but after editing, when I press “Save” the Grid is back to before changes and there is no change in the database. SELECT is using 3 tables, UPDATE is supposed to update only the main one, but still nothing happens.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="idw" AllowSorting="True" DataSourceID="SqlDataSourceGrid">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="idw" HeaderText="idw" InsertVisible="False" ReadOnly="True" SortExpression="idw" />
<asp:BoundField DataField="name" HeaderText="name" ReadOnly="True" SortExpression="name" />
<asp:BoundField DataField="surname" HeaderText="surname" ReadOnly="True" SortExpression="surname" />
<asp:BoundField DataField="item_name" HeaderText="item_name" ReadOnly="True" SortExpression="item_name" />
<asp:BoundField DataField="item_serial" HeaderText="item_serial" ReadOnly="True" SortExpression="item_serial" />
<asp:BoundField DataField="date_taken" HeaderText="date_taken" SortExpression="date_taken" />
<asp:BoundField DataField="notes" HeaderText="notes" SortExpression="notes" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceGrid" runat="server" ConnectionString="<%$ ConnectionStrings:WarehouseConnectionString %>"
SelectCommand="SELECT idw, name, surname, item_name, item_serial, date_taken, notes FROM Warehouse w JOIN Users u ON w.idu=u.idu JOIN Items i ON i.ids=i.ids"
UpdateCommand="UPDATE Warehouse SET date_taken=@date_taken, notes=@notes WHERE idw=@idw">
<UpdateParameters>
<asp:Parameter Name="date_taken" />
<asp:Parameter Name="notes" />
<asp:Parameter Name="idw" />
</UpdateParameters>
I’ve read multiple examples and tutorials and everything should be fine. I’ve “manually” written the SELECT and UPDATE commands in SqlDataSource, maybe that’s the problem?
Thanks in advance for any kind of advice.
I used code-behind solution in the end, manually coding:
Which might actually give me more control over data.