0

Couldn't insert the data into database using post method

This is for only one field insertion into the database

The data should be inserted only on button click 'Submit'

 $scope.btntext = "Submit";       
        $scope.submit = function () {           
            debugger;
            var post = $http({
                method: "POST",
                url: "http://stagingserver:85/EBSApi/api/Warehouse/AddInvoiceDetails",
                data: $scope.InvoiceId,
                dataType: 'json',
                headers: { "Content-Type": "application/json" }
            });
            post.success(function (data) {                
                debugger;
                $scope.id = data;
                //$scope.Selectedinvoice.originalObject.InvoiceId = $scope.data;              
                alert('Data Submitted...!');
            });
            //$scope.mydata = "";
            post.error(function (data) {
                debugger;                
                alert('Failed');
            });          
        } 
 [HttpPost]
        [ActionName("AddInvoiceDetails")]
        public void insertInvoiceDetails(int InvoiceId)
        {
            SqlConnection myConnection = new SqlConnection();
            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ERPConnectionString"].ConnectionString;
            SqlCommand sqlCmd = new SqlCommand();
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "INSERT_WAREHOUSE";
            sqlCmd.Connection = myConnection;
            sqlCmd.Parameters.AddWithValue("@InvoiceId", InvoiceId);
            //InvoiceDetails id = new InvoiceDetails();
            //sqlCmd.Parameters.AddWithValue("@PartNo", id.PartNo);
            //sqlCmd.Parameters.AddWithValue("@PartName", id.PartName);
            //sqlCmd.Parameters.AddWithValue("@NoOfPallets", id.NoOfPallets);
            //sqlCmd.Parameters.AddWithValue("@PalletCapacity", id.PalletCapacity);
            //sqlCmd.Parameters.AddWithValue("@Numbers", id.Numbers);
            myConnection.Open();
            int rowInserted = sqlCmd.ExecuteNonQuery();            
            myConnection.Close();          
        }  

I'm getting 404 not found in the console. The scope variable defined in the angularjs code is undefined.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • Possible duplicate of [Web Api HTTPPost not accepting int](https://stackoverflow.com/questions/42842805/web-api-httppost-not-accepting-int) – Bryan Dellinger Jun 20 '19 at 11:01
  • 1. `404` means your URL is not correct and so it cant be found. 2. Show me how you are setting value of `$scope.InvoiceId` . SHow HTML code as well. Its hard to guess from this much data – Shashank Vivek Jun 20 '19 at 11:47

0 Answers0