Insert data in database using Web API in AngularJS

on Jul 12, 2019 07:06 AM

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.

        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);
            int rowInserted = sqlCmd.ExecuteNonQuery();
            return 1;


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jul 15, 2019 06:21 AM
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