System.Data.SqlClient.SqlException: Could not find stored procedure

1

I'm trying to do a WebMethod that gets me all the information from a table.

public void HelloWorld()
        {
            var Lista = new List<Atributos>();
            using (var con = new SqlConnection(cnn))
            {
                var cmd = new SqlCommand("SELECT * FROM ASIGNATURA", con) { CommandType = CommandType.StoredProcedure };
                con.Open();
                var dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    var hambre = new Atributos
                    {
                        iD = Convert.ToInt32(dr[0].ToString()),
                        Nombre = dr[1].ToString(),
                        Credito = Convert.ToInt32(dr[2].ToString())

                    };
                    Lista.Add(hambre);
                }
            }
            var js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(Lista));
        }

This is the Attributes class:

public class Atributos
    {
        public int iD { get; set; }
        public string Nombre { get; set; }
        public int Credito { get; set; }
    }

This is the table Subject

But I get this error and I do not know how to solve it. I do not even understand why the error occurs.

I hope someone helps me! Thanks !!

    
asked by java005 15.11.2018 в 23:01
source

2 answers

2

Try removing it

 { CommandType = CommandType.StoredProcedure };


 var cmd = new SqlCommand("SELECT * FROM ASIGNATURA", con);
                con.Open();

You are calling a sql statement, not a storage procedure.

    
answered by 15.11.2018 / 23:06
source
-1

the error is in:

var cmd = new SqlCommand ("SELECT * FROM SUBJECT;", with) {CommandType = CommandType.StoredProcedure};

you still have to add the; at the end of the query.

I hope it serves you.

    
answered by 15.11.2018 в 23:05