Home>

Here is the appsettings.json file: `{

"ConnectionStrings": {
    "EmployeeAppCon": "Server= (localdb) \\ mssqllocaldb; Database= EmployeeDB; Trusted_Connection= true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
} `

I want to make a Web Api that bi add tasks and the date until which I have to execute it. When I start the project, the System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword' from '. Here's another DepartmentController.cs file:

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace WebApi.Controllers
{
    [Route ("api /[controller]")]
    [ApiController]
    public class DepartmentController: ControllerBase
    {
        private readonly IConfiguration_configuration;
        public DepartmentController (IConfiguration configuration)
        {
            _configuration= configuration;
        }
        [HttpGet]
        public JsonResult Get ()
        {
            string query= @ "
                     select DepartmentID, DepartmentName from dbo.Department ";
            DataTable table= new DataTable ();
            string sqlDataSource= _configuration.GetConnectionString ("EmployeeAppCon");
            SqlDataReader myReader;
            using (SqlConnection myCon= new SqlConnection (sqlDataSource))
            {
                myCon.Open ();
                using (SqlCommand myCommand= new SqlCommand (query, myCon))
                {
                    myReader= myCommand.ExecuteReader ();
                    table.Load (myReader); ;
                    myReader.Close ();
                    myCon.Close ();
                }
            }
            return new JsonResult (table);
        }
    }
}
`

In the word select the letter c is Russian.

Alexander Petrov2021-11-13 21:42:10

Chel ti genius, thank you

sanchosmore2021-11-13 21:42:10