我已經使用Visual Studio 2008 ASP.NET AccessDataSource嚮導來生成更新命令。 GridView編輯按鈕的作品。但是,當我點擊Gridview中的更新鏈接時,我收到以下消息:System.Data.OleDb.OleDbException:沒有給出一個或多個所需參數的值
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>
它似乎產生這一點,因爲我檢查了選項「使用樂觀併發」。如果我沒有選中它會產生你說的話,否則它會起作用。 – user310291 2010-03-07 14:19:13