0

Multi select option list image I Use a multi select option list and create a save button. write a query like that is INSERT and UPDATE same action occur on single save button.My sql query like this below,

UPDATE Demo
SET ApprovalPathName=@ApprovalPathName,
    LevelID=@LevelID
WHERE ProjectID=@ProjectID
  and Ordering=@Ordering
IF @@ROWCOUNT = 0
    insert into Demo(ApprovalPathName,LevelID,Ordering,ProjectID)   
    VALUES(@ApprovalPathName,@LevelID,@Ordering,@ProjectID)

As the picture, 3 data insert on my Demo table like this,

Database demo table image

The problem I faced an example like that from selected multi option list if i deleted or unselect or remove the last value and save it to database then upper selected 2 value updated but last value which one i remove on frontend and previously store in on DB not deleted. So, i want to write a query like that "only selected value updated if which one not used also remove from frontend multi select option but previously its inserted , it's will deleted"

Here is FrontEnd code with script

function fab_editgrppath() {            
        setTimeout(function () {
            for (var i = 0; i < pathnameval.length; i++) {

                //var fab_pathname = pathname;
                //var path_name = fab_pathname[i];
                var fab_pathnameval = pathnameval;
                var LevelID = fab_pathnameval[i];
                ordering = i + 1;

                var obj = new Object();
                obj.LevelID = LevelID;
                obj.ordering = ordering;
                obj.ProjectID = $('#projectid').val();
                obj.ApprovalPathName = fabapprovalpathname;
                obj.Mode = 'FABPATHEDITGRPLEVEL';

                var DBSP = new DB_SP_CONNECT();
                DBSP.ProcedureName = "POMS_POApprovalLevelProc";
                DBSP.obj = obj;
                DBSP.isasync = false;
                var o = DBSP.call_DB_Procedure();
                o = o.data;

                notify('Saved successfully.', 'GREEN');


            }
            fabricationpathlevelset();

        }, 200);                        
}

<div class="sm-3"><div class="form-group"><div class="row"><label for="selectTo">Selected</label></div><div class="row"><select name="selectTo" id="selectTo" size="5" class="form-control input-medium" multiple="multiple">@Html.Raw(ViewData["GetSelectedGrpOnFabPath"])</select></div></div></div><button type="button" class="btn btn-default w-100" onclick="fab_editgrppath();">Save</button>
SOUMIK
  • 1
  • 4
  • As per your `SQL` once you are not selecting the value from the list on `frontend` there is not statement seen on `SQL` for delete operation. You are just `updating` and `inserting`. So need to write `delete` statement as well. – Md Farid Uddin Kiron Apr 29 '22 at 07:51
  • What you can do is, send both `Ids` along with `selected` `true and false` status. Then based on that execute `UPDATE, INSERT and DELETE` operations. – Md Farid Uddin Kiron Apr 29 '22 at 07:56
  • As you said that if {//true then update and delete} else {//false insert} . But how to recognize the database is which one will delete – SOUMIK Apr 29 '22 at 08:08
  • Haha no worries, share your both frontend and backend code upto this point, I will help you to implement rest of the steps. – Md Farid Uddin Kiron Apr 29 '22 at 08:19
  • The `Ids` without `true/false` status will be deleted. Hope you got the point. – Md Farid Uddin Kiron Apr 29 '22 at 08:36
  • Sir,below in answer area i attached my code – SOUMIK Apr 29 '22 at 10:38
  • Not in answer section, add this on your question by modifying that and delete from answer. In addition include your controller and relavant class and model to reproduce the issue accordingly. – Md Farid Uddin Kiron Apr 29 '22 at 11:16
  • its done sir, just check it out – SOUMIK Apr 29 '22 at 11:36
  • I cannot see your other related snippet In addition your views is incomplete. Post your question [`like this sample](https://stackoverflow.com/questions/71899356/asp-net-mvc-get-the-url-and-view-the-image-as-it-changes`) – Md Farid Uddin Kiron Apr 29 '22 at 12:00
  • https://jsfiddle.net/Steve_Coffman/JS7HP/ – SOUMIK Apr 29 '22 at 13:42
  • this is my front end design additionly I add a save button with onclick function "fab_editgrppath()" based on selected list and those item will insert or update.Suppose if first time i insert 3 items into database next time if i remove the last item from frontend selected list and save again then the last item of database not deleted.From this fab_editgrppath() function all working fine but I want to change my query .I think this is the query problem. – SOUMIK Apr 29 '22 at 13:54

0 Answers0