Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
Sorry i posted this in the discussion which i think is a wrong place and i repost here.

I do not know where is going wrong but i seems not able to insert data using web api. Any help greatly appreciated and thanks a lot

The data
{"ID":1,"EmailAddress":"demo@demo.com"}


and the code:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Dapper;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace cirqer.Controllers.api
{

    public class EmailListList
    { 
        public int ID { get; set; }
        public string EmailAddress { get; set; }
    }

    public class emaillistController : ApiController
    {
        static string connectionstring = ConfigurationManager.ConnectionStrings["CRConnectionString"].ConnectionString;

        [HttpGet]
        public Int16 EmailList_SelectCount()
        {
            try
            {
                using (var conn = new SqlConnection(connectionstring))
                {
                    Int16 x = conn.ExecuteScalar("EmailList_SelectCount", commandType: CommandType.StoredProcedure);
                    return x;
                }
            }
            catch
            {
                return 0;
            }
        }

        [HttpPost]
        public void EmailList_Insert(EmailListList email)
        {
            try
            {
                // dynamic data = email; 
                using (var conn = new SqlConnection(connectionstring))
                {
                    conn.Open();
                    conn.Execute("EmailList_Insert", email, commandType: CommandType.StoredProcedure);
                    conn.Close();
                }
            }
            catch
            {
            }
        }


What I have tried:

Using telerik fiddler to simulate insert but failed.
Posted
Updated 2-Jul-16 6:02am
v3

1 solution

Remove the try/catch blocks. Your code is probably throwing exceptions but since you have everything in try/catch blocks and the catch sections don't have any code to log exceptions anywhere the exceptions are just being quitely swallowed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900