0

是否可以仅在其中一个字段实际更改时才触发 UpdateCommand ?其中一个字段是时间戳,除非其中一个字段值实际更改,否则我不希望更新时间戳?

这是 ASP 前端,在 CodeBehind 中没有任何相关内容。不确定是否重要,但我使用的是 Infragistics WebDataGrid 控件。

这是线条,如果您需要更多线条,请告诉我:

    <asp:SqlDataSource ID="tblClaimRoster" runat="server" 
        ConnectionString="<%$ ConnectionStrings:RosterConnectionString %>"
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT RosterID, [EE Name] AS EE_Name, [EEID], [Mgr Name] AS Mgr_Name, [Adjustment trained] AS Adjustment_trained, [Appeal trained] AS Appeal_trained, [ARGUS], [Auto Reversal] AS Auto_Reversal, [CBH D G] AS CBH_D_G, [CBH Proclaim] AS CBH_Proclaim, [CCE Tool Access] AS CCE_Tool_Access, [CCP], [CCR], [Checks Rework] AS Checks_Rework, [Chiro Occ Phys Home] AS Chiro_Occ_Phys_Home, [RA], [RDE], [Puerto Rico] AS Puerto_Rico, [Speech Vision Therapy] AS Speech_Vision_Therapy, [Stop Loss Calc] AS Stop_Loss_Calc, [Surg Anes] AS Surg_Anes, [Transplant], [Non Standard Contracts] AS Non_Standard_Contracts, [One View] AS One_View, [Pharmacy], [PMHS], [Post Pricing] AS Post_Pricing, [Pre D] AS Pre_D, [Proclaim], [Lifesource], [Maternity], [Medicare Hospital] AS Medicare_Hospital, [Medicaid], [Medicare Physician] AS Medicare_Physician, [MSP], [Negative Balance] AS Negative_Balance, [Foreign Claim] AS Foreign_Claim, [Hospital Standard] AS Hospital_Standard, [iCare], [ILWU], [iSave], [iView], [iTrack], [Correspondence trained] AS Correspondence_trained, [Defined Care] AS Defined_Care, [Dental Dentacom] AS Dental_Dentacom, [Dental Webster] AS Dental_Webster, [Dialysis], [ECPP], [Virgin Islands] AS Virgin_Islands, [Facets], [cFunds], [SAR], [Alliance], [MERPS], [Proclaim Green Screens] AS Proclaim_Green_Screens, [tblclaimRoster_Status], [Skill 1] AS Skill_1, [Skill 2] AS Skill_2, [Medicom], [CIGNA Claims] AS CIGNA_Claims, [Effective date in current role] AS Effective_date_in_current_role, [Time Stamp] AS Time_Stamp, [MSDRG], [ALI], [Call Trained] AS Call_Trained, [Dedicated Acct Taft Hartley] AS Dedicated_Acct_Taft_Hartley, [Dedicated Acct SOI] AS Dedicated_Acct_SOI, [SANP], [Dedicated Acct J J] AS Dedicated_Acct_J_J, [Xprtr], [VOB], [Hospital Non Standard] AS Hospital_Non_Standard FROM [tblclaimRoster] ORDER BY [EE Name] ASC"
        UpdateCommand="UPDATE [tblclaimRoster] SET [EE Name] = @EE_Name, [EEID] = @EEID, [Mgr Name] = @Mgr_Name, [Adjustment trained] = @Adjustment_trained, [Appeal trained] = @Appeal_trained, [ARGUS] = @ARGUS, [Auto Reversal] = @Auto_Reversal, [CBH D G] = @CBH_D_G, [CBH Proclaim] = @CBH_Proclaim, [CCE Tool Access] = @CCE_Tool_Access, [CCP] = @CCP, [CCR] = @CCR, [Checks Rework] = @Checks_Rework, [Chiro Occ Phys Home] = @Chiro_Occ_Phys_Home, [RA] = @RA, [RDE] = @RDE, [Puerto Rico] = @Puerto_Rico, [Speech Vision Therapy] = @Speech_Vision_Therapy, [Stop Loss Calc] = @Stop_Loss_Calc, [Surg Anes] = @Surg_Anes, [Transplant] = @Transplant, [Non Standard Contracts] = @Non_Standard_Contracts, [One View] = @One_View, [Pharmacy] = @Pharmacy, [PMHS] = @PMHS, [Post Pricing] = @Post_Pricing, [Pre D] = @Pre_D, [Proclaim] = @Proclaim, [Lifesource] = @Lifesource, [Maternity] = @Maternity, [Medicare Hospital] = @Medicare_Hospital, [Medicaid] = @Medicaid, [Medicare Physician] = @Medicare_Physician, [MSP] = @MSP, [Negative Balance] = @Negative_Balance, [Foreign Claim] = @Foreign_Claim, [Hospital Standard] = @Hospital_Standard, [iCare] = @iCare, [ILWU] = @ILWU, [iSave] = @iSave, [iView] = @iView, [iTrack] = @iTrack, [Correspondence trained] = @Correspondence_trained, [Defined Care] = @Defined_Care, [Dental Dentacom] = @Dental_Dentacom, [Dental Webster] = @Dental_Webster, [Dialysis] = @Dialysis, [ECPP] = @ECPP, [Virgin Islands] = @Virgin_Islands, [Facets] = @Facets, [cFunds] = @cFunds, [SAR] = @SAR, [Alliance] = @Alliance, [MERPS] = @MERPS, [Proclaim Green Screens] = @Proclaim_Green_Screens, [tblclaimRoster_Status] = @tblclaimRoster_Status, [Skill 1] = @Skill_1, [Skill 2] = @Skill_2, [Medicom] = @Medicom, [CIGNA Claims] = @CIGNA_Claims, [Effective date in current role] = @Effective_date_in_current_role, [Time Stamp] = GetDate(), [MSDRG] = @MSDRG, [ALI] = @ALI, [Call Trained] = @Call_Trained, [Dedicated Acct Taft Hartley] = @Dedicated_Acct_Taft_Hartley, [Dedicated Acct SOI] = @Dedicated_Acct_SOI, [SANP] = @SANP, [Dedicated Acct J J] = @Dedicated_Acct_J_J, [Xprtr] = @Xprtr, [VOB] = @VOB, [Hospital Non Standard] = @Hospital_Non_Standard WHERE [RosterID] = @RosterID">
    </asp:SqlDataSource>

抱歉,字段列表过长,但时间戳一已接近尾声。

编辑:附件是 2 张显示数组顺序的图像。 新价值观 新价值观 2


旧值 旧价值观 2

4

2 回答 2

1

OnRowUpdating使用在更新即将完成之前调用的 GridView事件。您可以检查您的值并取消更新操作。

在此事件处理程序中,您 作为参数OnRowUpdating 传递。GridViewUpdateEventArgs这提供了两个属性:NewValues获取新/更新的值和OldValues获取旧值,您将根据新值检查这些值。[注意使用e.NewValues& e.OldValues]

您通过设置取消更新操作e.Cancel=true

也参考 MSDN

<asp:GridView ID="CustomersGrid" runat="server" AutoGenerateColumns="true" 
  AllowSorting="true"   OnRowUpdating="CustomersGrid_Updating"
  AutoGenerateEditButton="true" DataSourceID="SqlDataSourceCustomers">
</asp:GridView>

下面的代码对我来说完全没问题

protected void CustomersGrid_Updating ( Object source, GridViewUpdateEventArgs e )
{

bool cancel = true;
object[] keysNewValues = (object[])Array.CreateInstance(typeof(object), e.NewValues.Count);
e.NewValues.Keys.CopyTo(keysNewValues, 0);

object[] keysOldValues = (object[])Array.CreateInstance(typeof(object), e.OldValues.Count);
e.OldValues.Keys.CopyTo(keysOldValues, 0);

 for (int i=0; i<keysNewValues.Count(); i++)
    {
     if ((e.NewValues[keysNewValues[i]] != null) && (e.OldValues[keysOldValues[i]] != null))
        { 

     if ( !(e.NewValues[keysNewValues[i]].ToString().Equals(e.OldValues[keysOldValues[i]])))
    // set cancel to false since you now have atleast one value which is changed
                        cancel = false;
        }
if ((e.NewValues[keysNewValues[i]] != null) && (e.OldValues[keysOldValues[i]] == null))
            {
                cancel = false;
            }
if ((e.NewValues[keysNewValues[i]] == null) && (e.OldValues[keysOldValues[i]] != null))
            {
                cancel = false;
            }
     }


     if (cancel)
      e.Cancel = true;

    }

确保,如果设置了 Newvalue null,则 Column 允许为 null ,否则它将引发异常。尽管随后需要使用 Try & Catch 块对其进行处理。 如果任何值为 null (OLD & NEW 值),则它的出现是null因为e.NewValues集合的类型为 : system.collections.specialized.ordereddictionary。还从下面的调试中检查:

在此处输入图像描述

于 2013-08-12T17:41:28.647 回答
0

我能想到的唯一方法是实际比较WHERE零件中的每个字段,时间戳字段除外

示例代码:

UPDATE [tblclaimRoster] 
SET [EE Name] = @EE_Name,
    [EEID] = @EEID,
    [Mgr Name] = @Mgr_Name,
    ...
WHERE
    [RosterID] = @RosterID AND
    ([EE Name] <> @EE_Name OR [Mgr Name] <> @Mgr_Name OR ...)
于 2013-08-12T13:48:08.963 回答