简体   繁体   中英

No value given for one or more required parameters ERROR

I'm aware that this question has been asked before. I have looked through them in hopes to find a reason I'm having issues.

I keep getting this error whenever I try to delete a user from a table within my form. I can edit them, I just can't delete them. I have done research to try and figure it out with no luck.

html code:

        <div align="center">
    <asp:Label ID="Label1" runat="server" Text="Manage Users"></asp:Label>
<p>
    <asp:Label ID="Label2" runat="server" Text="User Name:"></asp:Label>
    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</p>
<p>
    <asp:Label ID="Label3" runat="server" Text="Password:"></asp:Label>
    <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
</p>
        <p>
            <asp:Label ID="Label4" runat="server" Text="Security Level:"></asp:Label>
            <asp:DropDownList ID="drpdwnlstSecurityLevel" runat="server" 
                onselectedindexchanged="drpdwnlstSecurityLevel_SelectedIndexChanged">
                <asp:ListItem>A</asp:ListItem>
                <asp:ListItem>U</asp:ListItem>
            </asp:DropDownList>
</p>
        <p>
            <asp:Button ID="btnAddUser" runat="server" onclick="btnAddUser_Click1" 
    Text="Add User" /> 


</p>
        <p>
            <asp:Label ID="lblError" runat="server"></asp:Label>
</p>

    </div>
<p>
    &nbsp;</p>
            <div align="center">
<asp:GridView ID="tblUserLogin" runat="server" AutoGenerateColumns="False" 
    DataSourceID="AccessDataSource1">
    <Columns>
        <asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False" 
            SortExpression="UserID"></asp:BoundField>
        <asp:BoundField DataField="UserName" HeaderText="UserName" 
            SortExpression="UserName"></asp:BoundField>
        <asp:BoundField DataField="UserPassword" HeaderText="UserPassword" 
            SortExpression="UserPassword"></asp:BoundField>
        <asp:BoundField DataField="SecurityLevel" HeaderText="SecurityLevel" 
            SortExpression="SecurityLevel"></asp:BoundField>




        <asp:CommandField ShowEditButton="True"></asp:CommandField>
        <asp:CommandField ShowDeleteButton="True"></asp:CommandField>




    </Columns>
</asp:GridView>
                <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                    DataFile="~/PayrollSystem_DB.mdb" 

                    SelectCommand="SELECT [UserID], [UserName], [UserPassword], [SecurityLevel] FROM [tblUserLogin]" 
                    DeleteCommand="DELETE FROM [tblUserLogin] WHERE [UserID] = ?" 
                    InsertCommand="INSERT INTO [tblUserLogin] ([UserID], [UserName], [UserPassword], [SecurityLevel]) VALUES (?, ?, ?, ?)" 
                    UpdateCommand="UPDATE [tblUserLogin] SET [UserName] = ?, [UserPassword] = ?, [SecurityLevel] = ? WHERE [UserID] = ?">
                    <DeleteParameters>
                        <asp:Parameter Name="UserID" Type="Int32" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="UserName" Type="String" />
                        <asp:Parameter Name="UserPassword" Type="String" />
                        <asp:Parameter Name="SecurityLevel" Type="String" />
                        <asp:Parameter Name="UserID" Type="Int32" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="UserID" Type="Int32" />
                        <asp:Parameter Name="UserName" Type="String" />
                        <asp:Parameter Name="UserPassword" Type="String" />
                        <asp:Parameter Name="SecurityLevel" Type="String" />
                    </InsertParameters>
                </asp:AccessDataSource>

                </form>

</body>

You need to set the DataKeyNames property of the gridview:

datakeynames="UserID"

According to the MSDN documentation :

"You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work. The values of these key fields are passed to the data source control in order to specify the row to update or delete."

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM