public Modelreg getRegistro(int id) { Modelreg registro = new Modelreg(); conexion.Open(); SqlCommand command = new SqlCommand("SELECT * FROM [challenge].[dbo].[registro] WHERE[Id] = " + id, conexion); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { registro.Id = id; registro.email = reader["email"].ToString(); registro.name = reader["name"].ToString(); registro.idTraza = reader["idtrasa"].ToString(); registro.busy = Convert.ToBoolean(reader["ended"].ToString()); registro.attender = Convert.ToInt32(reader["userattender"].ToString()); } } conexion.Close(); return(registro); }
public List <Modelreg> getUsersSA() { List <Modelreg> users = new List <Modelreg>(); conexion.Open(); string sql = "SELECT * FROM [challenge].[dbo].[registro]" + "WHERE[ended] = 0 AND[userattender] = 1"; SqlCommand command = new SqlCommand(sql, conexion); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Modelreg usr = new Modelreg(); usr.Id = Convert.ToInt32(reader["Id"].ToString()); usr.name = reader["name"].ToString(); usr.email = reader["email"].ToString(); usr.idTraza = reader["idtrasa"].ToString(); users.Add(usr); } } conexion.Close(); return(users); }
public Modelreg registrar(string name, string email) { Modelreg registro = new Modelreg(); int IdNuevo = 0; string sql = "INSERT INTO [dbo].[registro]" + "([name]" + ",[email]" + ",[idtrasa]" + ",[ended]" + ",[userattender]) VALUES" + "('" + name + "', '" + email + "'" + ", CONCAT(rand(), '')" + ", 0" + ", 1) SELECT SCOPE_IDENTITY()"; SqlCommand command = new SqlCommand(); command.Connection = conexion; command.CommandType = CommandType.Text; command.CommandText = sql; try { conexion.Open(); var IdNueva = command.ExecuteScalar(); IdNuevo = Convert.ToInt32(IdNueva); } catch (SqlException ex) { // error here } finally { conexion.Close(); } registro = getRegistro(IdNuevo); return(registro); }