gpt4 book ai didi

c# - 没有为一个或多个必需参数提供值 ERROR

转载 作者:行者123 更新时间:2023-11-30 15:41:27 25 4
gpt4 key购买 nike

我知道之前有人问过这个问题。我仔细查看了它们,希望找到我遇到问题的原因。

每当我尝试从表单中的表中删除用户时,我都会收到此错误。我可以编辑它们,我只是不能删除它们。我已经进行了研究,试图找出答案,但运气不佳。

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>

最佳答案

您需要设置 gridview 的 DataKeyNames 属性:

datakeynames="UserID"

根据MSDN documentation :

“您必须设置 DataKeyNames 属性,以便 GridView 控件的自动更新和删除功能起作用。这些键字段的值被传递到数据源控件,以指定要更新或删除的行。 "

关于c# - 没有为一个或多个必需参数提供值 ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8335714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com