我利用向导创建了“插入编辑更新”和“删除”语句。问题是它们在我的网格视图中不起作用。当我去使用它时,我收到一个错误:
没有给出一个或多个必需参数的值。
我想知道可能是什么问题?它可以查询和显示数据。
<LoggedInTemplate>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF">
<p style="font-size: 20px">Welcome Back!<br />
Begin Sharing and Reading Space Tips Below!
</p>
<p> Current Posts:
<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataKeyNames="Title">
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title"
ReadOnly="True" />
<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" />
<asp:BoundField DataField="Timeof" HeaderText="Date"
SortExpression="Timeof" />
<asp:BoundField DataField="Post" HeaderText="Post" SortExpression="Post" />
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Posts.mdb"
SelectCommand="SELECT * FROM [UserPost] ORDER BY [Timeof]"
DeleteCommand="DELETE FROM [UserPost] WHERE (([Title] = ?) OR ([Title] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [UserPost] ([Title], [User], [Timeof], [Post]) VALUES (?, ?, ?, ?)"
UpdateCommand="UPDATE [UserPost] SET [User] = ?, [Timeof] = ?, [Post] = ? WHERE (([Title] = ?) OR ([Title] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="Title" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="User" Type="String" />
<asp:Parameter Name="Timeof" Type="DateTime" />
<asp:Parameter Name="Post" Type="String" />
<asp:Parameter Name="Title" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="User" Type="String" />
<asp:Parameter Name="Timeof" Type="DateTime" />
<asp:Parameter Name="Post" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</p>
<table>
<tr><td> <asp:Label ID="Label1" runat="server" Text="User: "></asp:Label></td><td>
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
<tr><td><asp:Label ID="Label2" runat="server" Text="Title: "></asp:Label></td><td><asp:TextBox ID="TextBox2"
runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
<tr><td><asp:Label ID="Label3" runat="server" Text="Date: "></asp:Label></td><td> <asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox></td></tr>
<tr><td valign="top"><asp:Label ID="Label4" runat="server" Text="Story: "></asp:Label></td><td valign="top">
<asp:TextBox ID="TextBox4" runat="server" Height="129px" Width="474px"
TextMode="MultiLine"></asp:TextBox></td></tr>
</table>
<asp:Button ID="makepost" runat="server" Text="Post My Tip/Story"
ValidationGroup="createpost" onclick="makepost_Click" /><br />
</div>
</LoggedInTemplate><AnonymousTemplate>
<asp:Login ID="Login1" runat="server" ForeColor="White">
</asp:Login><br /><div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#FFFFFF">Please Register to be begin viewing and sharing your
<br />Star Wars Old Republic Tips and Stories!</div>
</AnonymousTemplate>
</asp:LoginView>
答案 0 :(得分:1)
我现在对访问权限不是很好,但正如我在DeleteCommand中看到(并经过测试)你指定2个参数但只声明1,这与命名参数的SQL Server不同,你可以使用一个参数在查询中有很多时间,在UpdateCommand中发生相同但有更多参数...请参见Where语句。
尝试做这样的事情:
DeleteCommand="DELETE FROM UserPost WHERE (Title = ?)"
UpdateCommand="UPDATE UserPost SET [User] = ?, Timeof = ?, Post = ? WHERE (Title = ?)"
我测试过它。
编辑:您的表中大多数都有一个ID(唯一主键)可以使用它而不是标题字段。