2012-10-03 146 views
1
CREATE TRIGGER copy_pk_into_fk_trigger 
    AFTER insert ON tableA 
    FOR EACH ROW 
    BEGIN 
     insert into tableB (tblA_ID) values (new.tblA_ID); 
END$$ 

我使用上述觸發從表A和插圖主鍵值複製到tableB的爲外鍵。但在那之後,每當我編輯在ASP.net使用DetailsView控件TableB中的記錄,外鍵的值變爲「NULL」。這導致父母和孩子之間沒有更多的聯繫。 PLZ幫助我。複製主鍵值到另一個表作爲外鍵?

[TABLEA有西:tblA_ID,tblA_val和
表B中含有tblB_ID,tblA_ID,tblB_str
等等等等]

回答

0

我不認爲這有什麼與你的扳機。由於觸發器只會在插入被觸發後才運行。你可以告訴我在detailsView中更新的查詢嗎?你確定你沒有提到的更新語句呢?

+0

plz幫助。當我設置主要和Freign重點領域的「可見=假」更新不能正常工作。 – Awaidus

0

這裏的SqlDataSource和DetailsView控件完整的源代碼:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HADIConnectionString %>" 
      DeleteCommand="DELETE FROM &quot;INDENT_FILE_NO&quot; WHERE &quot;FILE_NO_ID&quot; = :original_FILE_NO_ID AND ((&quot;INDENT_ID&quot; = :original_INDENT_ID) OR (&quot;INDENT_ID&quot; IS NULL AND :original_INDENT_ID IS NULL)) AND ((&quot;FILE_NO&quot; = :original_FILE_NO) OR (&quot;FILE_NO&quot; IS NULL AND :original_FILE_NO IS NULL)) AND ((&quot;FILE_DESCRIPTION&quot; = :original_FILE_DESCRIPTION) OR (&quot;FILE_DESCRIPTION&quot; IS NULL AND :original_FILE_DESCRIPTION IS NULL)) AND ((&quot;INDENTER&quot; = :original_INDENTER) OR (&quot;INDENTER&quot; IS NULL AND :original_INDENTER IS NULL))" InsertCommand="INSERT INTO &quot;INDENT_FILE_NO&quot; (&quot;FILE_NO_ID&quot;, &quot;INDENT_ID&quot;, &quot;FILE_NO&quot;, &quot;FILE_DESCRIPTION&quot;, &quot;INDENTER&quot;) VALUES (:FILE_NO_ID, :INDENT_ID, :FILE_NO, :FILE_DESCRIPTION, :INDENTER)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:HADIConnectionString.ProviderName %>" 
      SelectCommand="SELECT * FROM &quot;INDENT_FILE_NO&quot; WHERE (&quot;INDENT_ID&quot; = :INDENT_ID)" 
      UpdateCommand="UPDATE &quot;INDENT_FILE_NO&quot; SET &quot;INDENT_ID&quot; = :INDENT_ID, &quot;FILE_NO&quot; = :FILE_NO, &quot;FILE_DESCRIPTION&quot; = :FILE_DESCRIPTION, &quot;INDENTER&quot; = :INDENTER WHERE &quot;FILE_NO_ID&quot; = :original_FILE_NO_ID AND ((&quot;INDENT_ID&quot; = :original_INDENT_ID) OR (&quot;INDENT_ID&quot; IS NULL AND :original_INDENT_ID IS NULL)) AND ((&quot;FILE_NO&quot; = :original_FILE_NO) OR (&quot;FILE_NO&quot; IS NULL AND :original_FILE_NO IS NULL)) AND ((&quot;FILE_DESCRIPTION&quot; = :original_FILE_DESCRIPTION) OR (&quot;FILE_DESCRIPTION&quot; IS NULL AND :original_FILE_DESCRIPTION IS NULL)) AND ((&quot;INDENTER&quot; = :original_INDENTER) OR (&quot;INDENTER&quot; IS NULL AND :original_INDENTER IS NULL))" ConflictDetection="CompareAllValues"> 

     <UpdateParameters> 
      <asp:Parameter Name="INDENT_ID" Type="Decimal" /> 
      <asp:Parameter Name="FILE_NO" Type="String" /> 
      <asp:Parameter Name="FILE_DESCRIPTION" Type="String" /> 
      <asp:Parameter Name="INDENTER" Type="String" /> 
      <asp:Parameter Name="original_FILE_NO_ID" Type="Decimal" /> 
      <asp:Parameter Name="original_INDENT_ID" Type="Decimal" /> 
      <asp:Parameter Name="original_FILE_NO" Type="String" /> 
      <asp:Parameter Name="original_FILE_DESCRIPTION" Type="String" /> 
      <asp:Parameter Name="original_INDENTER" Type="String" /> 
     </UpdateParameters> 

詳情查看:

<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" DataKeyNames="FILE_NO_ID" DataSourceID="SqlDataSource2" Height="50px" Width="287px" > 
         <Fields> 
          <asp:BoundField DataField="FILE_NO_ID" HeaderText="FILE_NO_ID" ReadOnly="True" SortExpression="FILE_NO_ID" Visible="False" /> 
          <asp:BoundField DataField="INDENT_ID" HeaderText="INDENT_ID" SortExpression="INDENT_ID" Visible="False" /> 
          <asp:BoundField DataField="FILE_NO" HeaderText="FILE_NO" SortExpression="FILE_NO" /> 
          <asp:BoundField DataField="FILE_DESCRIPTION" HeaderText="FILE_DESCRIPTION" SortExpression="FILE_DESCRIPTION" /> 
          <asp:BoundField DataField="INDENTER" HeaderText="INDENTER" SortExpression="INDENTER" /> 
          <asp:CommandField ShowEditButton="True" ButtonType="Button" /> 
         </Fields> 
        </asp:DetailsView> 

但是現在,當我按下編輯鍵和編輯字段,然後對其進行更新,數據的領域保持不變。意味着沒有行動需要。

相關問題