Named "CommandType" does not exist in current context

Can someone help me understand why I am getting this error here?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;

namespace JsPractice.Controllers
{
    public class SolutionController : Controller
    {

        public ActionResult Index ( )
        {

            return View();
        }

        [HttpPost]
        public ActionResult CreateNew ( int problem_id, string solver, string solution_code, string test_code )
        {
            // Going to move this to controller later .. 
            using ( SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalJsPracticeDb"].ConnectionString) )
            {
                using ( SqlCommand cmd = new SqlCommand("AddSolution", con) )
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@problem_id", problem_id);
                    cmd.Parameters.AddWithValue("@solver", solver);
                    cmd.Parameters.AddWithValue("@solution_code", solution_code);
                    cmd.Parameters.AddWithValue("@test_code", test_code);
                    con.Open();
                    cmd.ExecuteNonQuery();
                }

            }
            return View();
        }

    }
}

According to the documentation https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtype(v=vs.110).aspx I do not see what I am doing wrong, since I turned it on System.Data.SqlClient.

+4
source share
4 answers

You missed the inclusion of a namespace System.Data. Therefore, adding the following, you will solve your problem.

using System.Data;
+11
source

You have missed the namespace. add the line below.

using System.Data;

he will solve your problem.

+1

For this kind of error, right-click on the error word and say β€œResolve”. All errors will be associated with the assembly definition in your project.

0
source

Add using System.Dataat the top of the page or just click on the type of command - there you will see an icon similar to a lamp, click on it and addusing System.Data;

-1
source

Source: https://habr.com/ru/post/1624734/


All Articles