Page 1 of 1

Multiple Delete working only for 2 rows

Posted: Fri Dec 09, 2022 2:20 pm
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


Re: Multiple Delete working only for 2 rows

Posted: Sat Dec 10, 2022 9:46 am
by MichaelG

futureaxs wrote:

F12 (Dev. tools) showing following...

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


Re: Multiple Delete working only for 2 rows

Posted: Thu Dec 15, 2022 1:02 pm
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


Re: Multiple Delete working only for 2 rows

Posted: Thu Dec 15, 2022 2:30 pm
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.......


Re: Multiple Delete working only for 2 rows

Posted: Thu Dec 15, 2022 3:44 pm
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...


Re: Multiple Delete working only for 2 rows

Posted: Thu Dec 15, 2022 4:58 pm
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..


Re: Multiple Delete working only for 2 rows

Posted: Fri Dec 16, 2022 6:00 am
by Webmaster

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