![]() |
Pete K 1/22/2018 |
What I do is to set this up at the database level, which is foolproof. I use SQL Server. If you have your table relationships set up, you can specify what happens when the parent record is deleted or updated. For deletes, I choose "Cascade", which causes the dependent records in the child table to also be deleted at the same time the parent record gets deleted. The great thing about taking care of things like this at the DB level is that no matter where the delete occurs -- even in other apps/DB tools -- your referential integrity is always maintained. |
![]() |
jadachDevClub member 1/22/2018 |
What I do is to set this up at the database level, which is foolproof. I use SQL Server. If you have your table relationships set up, you can specify what happens when the parent record is deleted or updated. For deletes, I choose "Cascade", which causes the dependent records in the child table to also be deleted at the same time the parent record gets deleted. The great thing about taking care of things like this at the DB level is that no matter where the delete occurs -- even in other apps/DB tools -- your referential integrity is always maintained.
|
I
|
i.NoLim author 1/22/2018 |
Thank you very much for your replies. I have 2 questions,
|
![]() |
Pete K 1/22/2018 |
Thank you very much for your replies. I have 2 questions,
|
I
|
i.NoLim author 1/22/2018 |
No. Each relationship has it's own rules for handling updates and deletes. If you add this rule to the relationship that links [Applicant] to [Charges], it should have no effect on any other relationships. The [Family] table would not be affected at all.
|
I
|
i.NoLim author 1/22/2018 |
After some testing I figured out that the code above updates the whole DB, that's a problem. XSession.Session["APPLICANT_ID"]
DB.Query("UPDATE A SET A.SUB = C.CHARGESUM FROM APPLICANT A INNER JOIN( SELECT APPLICANTID, SUM(PAID) CHARGESUM FROM CHARGES C GROUP BY APPLICANTID)C ON A.APPLICANTID = " |
![]() |
jadachDevClub member 1/23/2018 |
Try something like this on before deleted event of Applicant Table: dynamic tblCHARGES = GlobalVars.dal.Table("dbo.CHARGES"); |
I
|
i.NoLim author 1/24/2018 |
Thank you jadach.
dynamic tblCharges = GlobalVars.dal.Table("dbo.CHARGES"); |
![]() |
Admin 1/24/2018 |
Looks like an issue with SQL Query you trying to execute. Instead of executing it print this query on the web page to see what exactly went wrong: |
I
|
i.NoLim author 1/24/2018 |
Thanks to everyone for your replies. I finally got it, further testing needed. At first I wrote the code in the "Before record updated" event but it was adding the values before the item was added/updated. So I thought, "well... I can just copy the code to the 'After record updated' event," no luck. I had to change data[""].ToString() to values[""].ToString(). Side question, whats the difference between "values" vs. "oldvalues?" Is "oldvalues" the value of the field before the update? string strSubsidy = "UPDATE A SET A.SUBSIDY = (SELECT SUM(PASS_PAID) CHARGESUM FROM CHARGES C WHERE C.APPLICANT_ID ='" + data["APPLICANT_ID"].ToString() + "')FROM APPLICANT A, CHARGES C WHERE A.APPLICANT_ID = '" + data["APPLICANT_ID"].ToString() + "'"; |