Angular delete a record from the database

user6440175

I am trying to delete a record from the database using angular services. I created a method in my mvc controller but I don't know how to call this method and pass the id.

    [HttpPost]
        public static void DeleteRecord(int settingID)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connStringApps))
                {
                    conn.Open();
                    using (SqlCommand command = new SqlCommand("DeleteCurrentRecord", conn))
                    {
                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        command.Parameters.Add("@SettingId", SqlDbType.VarChar).Value = settingID;
                        command.ExecuteNonQuery();
                        command.Parameters.Clear();
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }

        }


        myApp.service("deleteService", function ($rootScope) {
            this.removeRow = function (recId) {

            }
        });


         myApp.controller('myController', ['$scope','deleteService',
          function ($scope, deleteService) {

              $scope.deleteRecordFromDB = function (recId) {
                  //record id is the Id of the record that I want to delete
              }
              ;
          }
        ]);
rahulbhondave
  myApp.service("deleteService", function ($rootScope, $http) {
        this.removeRow = function (recId) {

        $http.delete(url, {params: {recordId:recId}})
        .success(function (data, status, headers, config) {
            window.location.reload();
        })
        .error(function (data, status, header, config) {
        });
      }
  });

  myApp.controller('myController', ['$scope', 'deleteService', function ($scope, deleteService) {
      $scope.deleteRecordFromDB = function (recId) {
          deleteService.removeRow(recId); 
      };
  }
  ]);

You can access recordId by HttpGet method on server side.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to delete duplicates record from a mongodb database

Record Won't Delete from SQLite Database

Delete record from database using AJAX

Delete record by using ajax from database EntityFramework

delete record from database without refreshing

delete a certain record from a rows in database

Delete record from database with Cloud Spanner

Laravel - Delete data record from Database

delete button delete record from the database but not from the frontend

laravel : After delete record from database the new record is in the place of the deleted record

How to delete a record from database where all fields are the same to another?

Laravel - Delete record from database if not exists in given array

laravel delete multiple record from different database at once

How to delete a specific record from database mysql by using Volley

Android: Delete record from remote database on app uninstall

Alert Message Does not Show in screen while a record delete from Database

cant delete record from database using $.ajax() function

Unable to delete record from database Entity Framework C#

How to delete a record from MySQL database using AJAX and PHP in Codeigniter

how to auto run a php script and delete a record from database

How to delete a record from a database in flask-SQLAlchemy?

How to properly delete a record from a database in one query? JPA

Delete record in database if checkbox is unchecked

Ecto delete referenced database record

jTable jquery Not Delete record in Database

Record not deleted from database

How to delete record from table using Angular http.delete with PHP backend?

How to delete record from selected row datagridview and update database after deleted?

In a snackbar action, how can I be sure it's safe to permanently delete a soft-deleted record from the database?