public static void addMSTicket(MegaSenaTicket ticket) { SqlConnection con = startConnection(); using (SqlCommand cmd = new SqlCommand("INSERT INTO RaffleTicket(numbers,raffle_id) output INSERTED.ID VALUES(@numbers,@fkey)", con)) { // cmd.Parameters.AddWithValue("@numbers", string.Join(" ", ticket.numbers)); cmd.Parameters.AddWithValue("@fkey", MSRaffle.id); int id = (int)cmd.ExecuteScalar(); ticket.id = id; con.Close(); } }
public static MegaSenaTicket[] getMSTickets() { List <MegaSenaTicket> tickets = new List <MegaSenaTicket>(); SqlConnection con = startConnection(); using (SqlCommand command = new SqlCommand("SELECT * FROM RaffleTicket", con)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { MegaSenaTicket ticket = new MegaSenaTicket(Convert.ToInt32(reader["id"]), Convert.ToDateTime(reader["date"]), Convert.ToString(reader["numbers"]), MSRaffle); tickets.Add(ticket); } } } con.Close(); return(tickets.ToArray()); }