locked
Update not working from Gridview RRS feed

  • Question

  • User1212918916 posted

    (Totally a noob here, so please be patiet)  I'm using SQL2008 and VB in Microsoft Visual Web Developer 2010 express.

    I have a gridview which returns the contents of a table once the tablename is selected from a dropdown.  To this extent, the gridview is working with a sproc.  What I'm hoping for now is to be able to update the data.  I added the update parameters to the datasource and the commandfield to the gridview.  when I click "edit" in the form, the fields are displayed properly and I can "attempt" to edit them.  Once I click update, the values I have changed go back to what they were.  there's nothing in my codebehind related to the sqldatasource or the gridview.

            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" 
                            DataSourceID="SQL_display_Sched" AutoGenerateColumns="False" >
                    <Columns>
                        <asp:BoundField DataField="RBT_ID" HeaderText="RBT_ID" InsertVisible="False" 
                                        ReadOnly="False" SortExpression="RBT_ID" Visible="True" />
                        <asp:BoundField DataField="SVR_ID" ReadOnly="True" HeaderText="HostNameD" SortExpression="SVR_ID" />
                        <asp:BoundField DataField="RBT_Flag" HeaderText="Reboot Flag (Y/N)" SortExpression="RBT_Flag" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:CommandField ShowEditButton="True" />
                    </Columns>
            </asp:GridView>
    
            <asp:SqlDataSource ID="SQL_display_Sched" runat="server" 
                ConnectionString="<%$ ConnectionStrings:SrvRebootsConnectionString %>" 
                    SelectCommand="sp_PICKTABLE" SelectCommandType="StoredProcedure" 
                    UpdateCommand="sp_UpdateTable" UpdateCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="DropDownList1" Name="TABLENAME" 
                                              PropertyName="SelectedValue" Type="String" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="TABLENAME" Type="String" />
                        <asp:Parameter Name="RBT_ID" Type="String" />
                        <asp:Parameter Name="RBT_Flag" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                    </UpdateParameters>
            </asp:SqlDataSource>

    Thursday, April 28, 2011 11:29 AM

Answers

All replies

  • User-1704326042 posted

    Hello,

    Try adding the DataKeyNames property.

    this property contains your table's primary key.

    Example : DataKeyNames="CustomerID"

    Here's a link to msdn on the property : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 28, 2011 11:58 AM
  • User1212918916 posted

    So in the 20 minutes since I posted this I learned a ton.  first, SQL profiler is your friend.  Second, you have to tell SQL what to do or it will do nothing.  I wasn't passing the table name to the sproc, so it didnt' know what to do.  Seeing the SQL code was all I needed.  Suddenly I see the light, and it was good.

    Thursday, April 28, 2011 12:22 PM
  • User-1704326042 posted

    :)

    SQL Profiler is our friend for sure :)

    Glad you solved it :)

    Thursday, April 28, 2011 12:32 PM