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 !!