public List<Totem> GetTotem()
{
List<Totem> lista = new List<Totem>();
try
{
using (SqlConnection conn = new SqlConnection(Connection.ConnString))
{
string SQL = string.Empty;
SQL += "SELECT id, dato1, dato2, dato3";
SQL += " FROM";
SQL += " mitabla";
conn.Open();
SqlCommand command = new SqlCommand(SQL, conn);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
sqlDataAdapter.Fill(dataset, "mitabla");
conn.Close();
foreach (DataRow row in dataset.Tables[0].Rows)
{
Totem objeto = new Totem();
objeto.Id = Convert.ToInt32(row["suc"].ToString());
objeto.Dato1 = row["dato1"].ToString();
objeto.Dato2 = row["dato2"].ToString();
objeto.Dato3 = row["dato3"].ToString();
lista.Add(Totemobjeto);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return lista;
}
ligero error dentro del foreach