Insert data in database using Web API in AngularJS

Last Reply 11 months ago By dharmendr

Posted 11 months ago

How to insert data into database based on textbox validations in angularjs?

If the textbox is empty and submit button is entered, the data must not be inserted, it also should throw an error message.

If the textbox contain some value and then submit button is pressed, the data should be inserted.

        [HttpPost]
        [ActionName("AddIssueDetails")]
        public int insertIssueDetails(IssueDetails id)
        {
            SqlConnection myConnection = new SqlConnection();
            myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ERPConnectionString"].ConnectionString;
            SqlCommand sqlCmd = new SqlCommand();
            DateTime now = DateTime.Now;
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "INSERT_WAREHOUSE_DETAILS";
            sqlCmd.Connection = myConnection;
            sqlCmd.Parameters.AddWithValue("@InvoiceId", id.InvoiceId);
            sqlCmd.Parameters.AddWithValue("@IssueDate", now);
            sqlCmd.Parameters.AddWithValue("@PackingListNo", id.PackingListNo);
            sqlCmd.Parameters.AddWithValue("@DispatchId", id.DispatchId);
            sqlCmd.Parameters.AddWithValue("@IssueQty", id.IssueQty);
            sqlCmd.Parameters.AddWithValue("@CreatedBy", id.CreatedBy);
            myConnection.Open();
            int rowInserted = sqlCmd.ExecuteNonQuery();
            myConnection.Close();
            return 1;
        }

 

You are viewing reply posted by: dharmendr 11 months ago.
Posted 11 months ago
skp says:
 public int insertIssueDetails(IssueDetails id)

Will you please let me know the values you are getting in the id object in the web api controller?

For insert update and delete you can refer below article also.

AngularJS Web API CRUD - Select Insert Edit Update and Delete using Web API and AngularJS in ASP.Net MVC