Exemple #1
0
        public void ExcluirCadastro(Cadastros cad)
        {
            MySqlConnection conn = new SqlConection().Criar();

            command = new MySqlCommand("DELETE FROM Cadastro where id = @id ", conn);
            command.Parameters.Add(new MySqlParameter("id", cad.id_cadastro));
            command.Prepare();
            try
            {
                command.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #2
0
        public List <Cadastros> ListarCadastro()
        {
            List <Cadastros> cad  = new List <Cadastros>();
            MySqlConnection  conn = new SqlConection().Criar();

            command = new MySqlCommand("SELECT * FROM cadastro", conn);
            try
            {
                MySqlDataReader dr = command.ExecuteReader();
                cad = ConvertDataReaderToList(dr);
            }
            finally
            {
                conn.Close();
            }
            return(cad);
        }
Exemple #3
0
        public void CadastrarCadastro(Cadastros cad)
        {
            MySqlConnection conn = new SqlConection().Criar();

            command = new MySqlCommand("INSERT INTO Cadastro (Nome, carro, placa, data) values (@nome, @carro, @placa, @data)", conn);
            command.Parameters.Add(new MySqlParameter("nome", cad.nome));
            command.Parameters.Add(new MySqlParameter("carro", cad.carro));
            command.Parameters.Add(new MySqlParameter("placa", cad.placa));
            command.Parameters.Add(new MySqlParameter("data", cad.data));
            command.Prepare();
            try
            {
                command.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #4
0
        public void Alterarcadastro(Cadastros cad)
        {
            MySqlConnection conn = new SqlConection().Criar();

            try
            {
                command = new MySqlCommand("update Cadastro set nome = ?, carro = ?, placa = ?, data =? where id = ?", conn);
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@nome", cad.nome);
                command.Parameters.AddWithValue("@carro", cad.carro);
                command.Parameters.AddWithValue("@id", cad.id_cadastro);
                command.Parameters.AddWithValue("@placa", cad.placa);
                command.Parameters.AddWithValue("@data", cad.data);

                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                conn.Close();
            }
            catch (Exception e)
            {
                throw new Exception("Erro {0}", e);
            }
        }