2011-12-01 74 views
3

我知道这个问题以前已经被问过。我已经浏览过他们,希望找到我遇到问题的原因。对于一个或多个所需参数没有给出值ERROR

每当我尝试从表单中的表中删除用户时,我总是收到此错误。我可以编辑它们,但我不能删除它们。我已经做了研究,试图找出它,但没有运气。

的html代码:

 <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> 

回答

4

你需要设置GridView控件的DataKeyNames属性:

datakeynames="UserID" 

按照MSDN documentation

“你必须设置DataKeyNames属性以便自动更新和删除ete的GridView控件的功能工作。这些关键字段的值传递给数据源控件,以指定要更新或删除的行。“

+0

非常感谢你。再多6分钟才能接受它作为答案。 – Mike

相关问题