how to call select query stored procedure in .net core api ?

Jun 24 2021 5:36 AM

Hi to all,

I created one stored procedure for select query where Id=user_id. And call that store Procedure it shows error profile_name parameter was not supplied. Please give me idea or solution to solve this.

   [HttpGet]
        public async Task<IActionResult> GetProfileDetails()
        {

            var username = HttpContext.User.Identity.Name;
            var user = await userManager.FindByNameAsync(username);
            var Id = user.Id;


            DataTable table = new DataTable();
            string sqlDataSource = _configuration.GetConnectionString("ConnStr");
            SqlDataReader myReader;
            using (SqlConnection myCon = new SqlConnection(sqlDataSource))
            {
                myCon.Open();
                using (SqlCommand myCommand = new SqlCommand("SP_getprofiledetails", myCon))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.Add(new SqlParameter("user_id", Id));
                    myReader = myCommand.ExecuteReader();
                  
                    table.Load(myReader); ;

                    myReader.Close();
                    myCon.Close();
                }
            }

            return new JsonResult(table);
        }
thank you in advance


Answers (1)