2011-12-01 71 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

相關問題