Multiple Delete working only for 2 rows

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
futureaxs
User
Posts: 16

Multiple Delete working only for 2 rows

Post by futureaxs »

I am using ASP.NET Maker 2022.8.0

I enabled "Multiple Delete" from asp.net > Page Options (Global).
After generating All pages (Tried delete all & fresh generate also) Can't able to delete more than 2 rows.

If I delete 2 rows it's working fine.
If I delete 3+ rows it's Not working. Page refreshing & Getting (Error - Delete Canceled)..

F12 (Dev. tools) showing following event.

RequestURL : domain/TableMasterDelete
RequestMethod : Post
Status Code : 302


MichaelG
User
Posts: 1095

Post by MichaelG »

futureaxs wrote:

F12 (Dev. tools) showing following...

If you use Chrome, check the Payload panel and check what data is posted.


futureaxs
User
Posts: 16

Post by futureaxs »

I Just tested in one more project receving same error.
for 2 rows it's working fine. more than 2 Error : Delete cancelled.

Just did with fresh DB & having only 1 table with random data..

Payload as follows...

csrf_name:
__RequestVerificationToken
__RequestVerificationToken: (random token)

action: delete

key_m[]: 4
key_m[]: 1
key_m[]: 3
key_m[]: 2


futureaxs
User
Posts: 16

Post by futureaxs »

Upon some debugging in VS 2022 i find there was a delete query problem.

query as follows
DELETE FROM [dbo].[table1] WHERE (([pkfield] = '1') OR ([pkfield] = '2') OR ([pkfield] = '7') AND [pkfield]=N'1') -- Success
DELETE FROM [dbo].[table1] WHERE (([pkfield] = '1') OR ([pkfield] = '2') OR ([pkfield] = '7') AND [pkfield]=N'2') -- Success
DELETE FROM [dbo].[table1] WHERE (([pkfield] = '1') OR ([pkfield] = '2') OR ([pkfield] = '7') AND [pkfield]=N'7') -- Failed

when i run same in select query in SSMS like
select * FROM [dbo].[table1] WHERE (([pkfield] = '1') OR ([pkfield] = '2') OR ([pkfield] = '7') AND [pkfield]=N'1')
i get first 2 rows (1,2) only
So code will check each row separately and failing at 3rd row and cancles at complete Multiple delete query...
it seems to be filter problem..

How do i overcome it.......


futureaxs
User
Posts: 16

Post by futureaxs »

New update --- Temp Solved it by Adding some opening & closing ()'s

table1.cs as follows
public async Task<int> DeleteAsync(
string sql = "DELETE FROM " + UpdateTable + " WHERE (";
(Old Code " WHERE" New Code " WHERE ("

aspnetfn.cs as follows
public static void AddFilter(ref string filter, string? newfilter, string cond = ") AND")
(Old Code "AND" New Code ") AND"

But the real problem is AddFilter() is not only apply to Delete but all others...


futureaxs
User
Posts: 16

Post by futureaxs »

Final update

<removed>
aspnetfn.cs as follows
public static void AddFilter(ref string filter, string? newfilter, string cond = ") AND")
(Old Code "AND" New Code ") AND"
<removed>

added in table1.cs
if (!Empty(filter))
{
filter= filter.Replace("AND", ") AND");
sql += filter;
}

Seems to be working fine....

Can this be update in template pls..


Webmaster
User
Posts: 9425

Post by Webmaster »

Please update to the latest template (Tools -> Update Template) and try again.


Post Reply