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$$
我正在使用上面的触发器将tableA和inset中的Primary Key值复制到tableB中作为外键。但在那之后,每当我使用ASP.net中的detailsView编辑tableB中的记录时,外键值变为“NULL”。这导致不再与父母和孩子建立联系。请帮助我。
[tableA有col:tblA_ID,tblA_val和
TableB包含tblB_ID,tblA_ID,tblB_str
等等]
答案 0 :(得分:0)
我不认为这与你的触发器有关。因为触发器仅在触发插入后运行。你能告诉我在detailsView中更新的查询吗?你确定你没有提到更新声明吗?
答案 1 :(得分:0)
这是SqlDATASource和DetailsView的完整源代码:
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HADIConnectionString %>"
DeleteCommand="DELETE FROM "INDENT_FILE_NO" WHERE "FILE_NO_ID" = :original_FILE_NO_ID AND (("INDENT_ID" = :original_INDENT_ID) OR ("INDENT_ID" IS NULL AND :original_INDENT_ID IS NULL)) AND (("FILE_NO" = :original_FILE_NO) OR ("FILE_NO" IS NULL AND :original_FILE_NO IS NULL)) AND (("FILE_DESCRIPTION" = :original_FILE_DESCRIPTION) OR ("FILE_DESCRIPTION" IS NULL AND :original_FILE_DESCRIPTION IS NULL)) AND (("INDENTER" = :original_INDENTER) OR ("INDENTER" IS NULL AND :original_INDENTER IS NULL))" InsertCommand="INSERT INTO "INDENT_FILE_NO" ("FILE_NO_ID", "INDENT_ID", "FILE_NO", "FILE_DESCRIPTION", "INDENTER") VALUES (:FILE_NO_ID, :INDENT_ID, :FILE_NO, :FILE_DESCRIPTION, :INDENTER)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:HADIConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM "INDENT_FILE_NO" WHERE ("INDENT_ID" = :INDENT_ID)"
UpdateCommand="UPDATE "INDENT_FILE_NO" SET "INDENT_ID" = :INDENT_ID, "FILE_NO" = :FILE_NO, "FILE_DESCRIPTION" = :FILE_DESCRIPTION, "INDENTER" = :INDENTER WHERE "FILE_NO_ID" = :original_FILE_NO_ID AND (("INDENT_ID" = :original_INDENT_ID) OR ("INDENT_ID" IS NULL AND :original_INDENT_ID IS NULL)) AND (("FILE_NO" = :original_FILE_NO) OR ("FILE_NO" IS NULL AND :original_FILE_NO IS NULL)) AND (("FILE_DESCRIPTION" = :original_FILE_DESCRIPTION) OR ("FILE_DESCRIPTION" IS NULL AND :original_FILE_DESCRIPTION IS NULL)) AND (("INDENTER" = :original_INDENTER) OR ("INDENTER" 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>
但现在,当我按下编辑按钮并编辑字段然后更新它们时,该字段的数据保持不变。意味着不采取行动。