gpt4 book ai didi

asp.net - 系统.Data.OleDb.OleDbException : No value given for one or more required parameters

转载 作者:行者123 更新时间:2023-12-05 09:00:18 24 4
gpt4 key购买 nike

我已使用 Visual Studio 2008 ASP.NET AccessDataSource 向导生成更新命令。 gridview 编辑按钮有效。但是,当我在 Gridview 中单击“更新链接”时,我收到以下消息:

System.Data.OleDb.OleDbException: No value given for one or more required parameters

向导有问题吗?

这是它生成的源代码:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True" DataKeyNames="Id"
DataSourceID="AccessDataSource1" PageSize="1">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="TaskName" HeaderText="TaskName"
SortExpression="TaskName" />
<asp:BoundField DataField="TaskDescription" HeaderText="TaskDescription"
SortExpression="TaskDescription" />
<asp:BoundField DataField="TaskPriority" HeaderText="TaskPriority"
SortExpression="TaskPriority" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
ConflictDetection="CompareAllValues" DataFile="~/App_Data/tasks.mdb"
DeleteCommand="DELETE FROM [Tasks] WHERE [Id] = ? AND (([TaskName] = ?) OR ([TaskName] IS NULL AND ? IS NULL)) AND (([TaskDescription] = ?) OR ([TaskDescription] IS NULL AND ? IS NULL)) AND (([TaskPriority] = ?) OR ([TaskPriority] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [Tasks] ([Id], [TaskName], [TaskDescription], [TaskPriority]) VALUES (?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Tasks]"
UpdateCommand="UPDATE [Tasks] SET [TaskName] = ?, [TaskDescription] = ?, [TaskPriority] = ? WHERE [Id] = ? AND (([TaskName] = ?) OR ([TaskName] IS NULL AND ? IS NULL)) AND (([TaskDescription] = ?) OR ([TaskDescription] IS NULL AND ? IS NULL)) AND (([TaskPriority] = ?) OR ([TaskPriority] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_TaskName" Type="String" />
<asp:Parameter Name="original_TaskDescription" Type="String" />
<asp:Parameter Name="original_TaskPriority" Type="Single" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="TaskName" Type="String" />
<asp:Parameter Name="TaskDescription" Type="String" />
<asp:Parameter Name="TaskPriority" Type="Single" />
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_TaskName" Type="String" />
<asp:Parameter Name="original_TaskDescription" Type="String" />
<asp:Parameter Name="original_TaskPriority" Type="Single" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="TaskName" Type="String" />
<asp:Parameter Name="TaskDescription" Type="String" />
<asp:Parameter Name="TaskPriority" Type="Single" />
</InsertParameters>
</asp:AccessDataSource>
</form>
</body>
</html>

最佳答案

根据我的经验,该错误消息通常表示列名称键入不正确。

我建议您逐步调试您的代码,并尝试在执行每个命令之前检查为每个命令生成的 SQL,一旦发生参数替换。

关于asp.net - 系统.Data.OleDb.OleDbException : No value given for one or more required parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2396255/

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