我正在使用asp.net中的Formview。我知道需要指定UpdateCommand,以便Formview知道要运行的SQL查询。
我是否需要在Formview设置的代码中添加 事件才能正确启动SQL查询?
另外,我没有得到SQL错误或任何东西,它只是没有绑定回数据库。
<EditItemTemplate>
ProductID:
<asp:Label ID="ProductIDLabel1" runat="server"
Text='<%# Eval("ProductID") %>' />
<br />
ProductName:
<asp:TextBox ID="ProductNameTextBox" runat="server"
Text='<%# Bind("ProductName") %>' />
<br />
UnitPrice:
<asp:TextBox ID="UnitPriceTextBox" runat="server"
Text='<%# Bind("UnitPrice") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
答案 0 :(得分:0)
确保设置DataKeys属性(通常设置为主键的列)。如果您需要更多帮助,则需要发布代码。
答案 1 :(得分:0)
我有类似的问题,然后我研究了MSDN,它说使用UpdateCommand与SqlDataSource,它的工作原理。
这是我的代码:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conString %>"
SelectCommand="SELECT DISTINCT * FROM [employees] WHERE ([username] = @username)"
UpdateCommand="UPDATE [employees] SET first_name = @first_name WHERE username = @username">