我翻遍了,研究了书籍,教程视频和大量文章,但我无法解决这个问题。在 Visual Studio 2010 中插入一个网格视图,我将数据源指定为访问数据库。在规范中,我包括插入、更新和删除记录的选项。网格视图出现在屏幕上,当我测试网页时,它会加载更新和插入等相关按钮。测试页面时,我单击更新按钮,更改一行,然后单击更新。页面恢复到以前的状态,记录保持不变。我刷新页面以确保它没有更新,它肯定没有。我完全按照教程进行操作,使用此方法时无法更新或删除字段。我使用的数据库是一个访问数据库,一个 mdb 文件。
我确定我在这里遗漏了一些非常简单的东西,但我不确定是什么。如果有人可以提供一些帮助,我将不胜感激!谢谢
这是我的表单代码。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Book Id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Book Id" HeaderText="Book Id" InsertVisible="False"
ReadOnly="True" SortExpression="Book Id" />
<asp:BoundField DataField="ISBN Number" HeaderText="ISBN Number"
SortExpression="ISBN Number" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Author" HeaderText="Author"
SortExpression="Author" />
<asp:BoundField DataField="Publisher" HeaderText="Publisher"
SortExpression="Publisher" />
<asp:BoundField DataField="Date Published" HeaderText="Date Published"
SortExpression="Date Published" />
<asp:CheckBoxField DataField="Availability" HeaderText="Availability"
SortExpression="Availability" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:booksellerConnectionString %>"
DeleteCommand="DELETE FROM [tblBooks] WHERE [Book Id] = ? AND (([ISBN Number] = ?) OR ([ISBN Number] IS NULL AND ? IS NULL)) AND (([Title] = ?) OR ([Title] IS NULL AND ? IS NULL)) AND (([Author] = ?) OR ([Author] IS NULL AND ? IS NULL)) AND (([Publisher] = ?) OR ([Publisher] IS NULL AND ? IS NULL)) AND (([Date Published] = ?) OR ([Date Published] IS NULL AND ? IS NULL)) AND [Availability] = ? AND (([Price] = ?) OR ([Price] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [tblBooks] ([Book Id], [ISBN Number], [Title], [Author], [Publisher], [Date Published], [Availability], [Price]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
ProviderName="<%$ ConnectionStrings:booksellerConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [tblBooks]"
UpdateCommand="UPDATE [tblBooks] SET [ISBN Number] = ?, [Title] = ?, [Author] = ?, [Publisher] = ?, [Date Published] = ?, [Availability] = ?, [Price] = ? WHERE [Book Id] = ? AND (([ISBN Number] = ?) OR ([ISBN Number] IS NULL AND ? IS NULL)) AND (([Title] = ?) OR ([Title] IS NULL AND ? IS NULL)) AND (([Author] = ?) OR ([Author] IS NULL AND ? IS NULL)) AND (([Publisher] = ?) OR ([Publisher] IS NULL AND ? IS NULL)) AND (([Date Published] = ?) OR ([Date Published] IS NULL AND ? IS NULL)) AND [Availability] = ? AND (([Price] = ?) OR ([Price] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Book_Id" Type="Int32" />
<asp:Parameter Name="original_ISBN_Number" Type="String" />
<asp:Parameter Name="original_ISBN_Number" Type="String" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Author" Type="String" />
<asp:Parameter Name="original_Author" Type="String" />
<asp:Parameter Name="original_Publisher" Type="String" />
<asp:Parameter Name="original_Publisher" Type="String" />
<asp:Parameter Name="original_Date_Published" Type="String" />
<asp:Parameter Name="original_Date_Published" Type="String" />
<asp:Parameter Name="original_Availability" Type="Boolean" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_Price" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Book_Id" Type="Int32" />
<asp:Parameter Name="ISBN_Number" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Author" Type="String" />
<asp:Parameter Name="Publisher" Type="String" />
<asp:Parameter Name="Date_Published" Type="String" />
<asp:Parameter Name="Availability" Type="Boolean" />
<asp:Parameter Name="Price" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ISBN_Number" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Author" Type="String" />
<asp:Parameter Name="Publisher" Type="String" />
<asp:Parameter Name="Date_Published" Type="String" />
<asp:Parameter Name="Availability" Type="Boolean" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="original_Book_Id" Type="Int32" />
<asp:Parameter Name="original_ISBN_Number" Type="String" />
<asp:Parameter Name="original_ISBN_Number" Type="String" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Author" Type="String" />
<asp:Parameter Name="original_Author" Type="String" />
<asp:Parameter Name="original_Publisher" Type="String" />
<asp:Parameter Name="original_Publisher" Type="String" />
<asp:Parameter Name="original_Date_Published" Type="String" />
<asp:Parameter Name="original_Date_Published" Type="String" />
<asp:Parameter Name="original_Availability" Type="Boolean" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_Price" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
下面的 asp.cs 文件;
namespace Second
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}