I have the following model with a method to retrieve a list of data of the same model.
public class Totem
{
public int Id { get; set; }
public string Dato1{ get; set; }
public string Dato2 { get; set; }
public string Dato3 { get; set; }
public List<Totem> GetTotem()
{
try
{
using (SqlConnection conn = new SqlConnection(Connection.ConnString))
{
string SQL = string.Empty;
SQL += "SELECT id, dato1, dato2, dato3";
SQL += " FROM";
SQL += " mitabla";
try
{
conn.Open();
SqlCommand command = new SqlCommand(SQL, conn);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
sqlDataAdapter.Fill(dataset, "mitabla");
conn.Close();
this.Id = Convert.ToInt32(dataset.Tables[0].Rows[0]["suc"].ToString());
this.Dato1= dataset.Tables[0].Rows[0]["dato1"].ToString();
this.Dato2 = dataset.Tables[0].Rows[0]["dato2"].ToString();
this.Dato3 = dataset.Tables[0].Rows[0]["dato3"].ToString();
}
catch (Exception)
{
throw;
}
}
}
catch (Exception)
{
throw;
}
}
}
Calling the GetTotem method from my controller should bring me a list of all the data I'm requesting (all data from the table of only those 4 fields) but I do not know how to return that list ...
Who can help me?