2009-07-30 44 views
0

我搞亂了asp.net中的Formview。我知道需要指定UpdateCommand,以便Formview知道要運行的SQL查詢。無法讓Formview更新,我做錯了什麼?

我需要編寫一個事件另外到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" /> 
     &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
      CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
    </EditItemTemplate> 
+0

你可以張貼一些代碼? – David 2009-07-30 21:04:33

+0

是你在updatepanel中的formview嗎? – 2009-07-31 03:53:02

回答

0

確保您設置的DataKeys屬性(通常是主鍵列(S))。如果您需要更多幫助,則需要發佈代碼。

0

我有類似的問題,然後我研究了MSDN,它說與SqlDataSource使用UpdateCommand,它的工作。
這裏是我的代碼:

<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">