コード例 #1
0
        public void Incluir(ModeloContato obj)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = conexao.ObjetoConexao;
            cmd.CommandText = "insert into contatos (NOME, EMAIL, TELEFONE) values (@nome, @email, @telefone); select @@IDENTITY";
            cmd.Parameters.AddWithValue("@nome", obj.NOME);
            cmd.Parameters.AddWithValue("@email", obj.EMAIL);
            cmd.Parameters.AddWithValue("@telefone", obj.TELEFONE);

            conexao.conectar();
            obj.ID = Convert.ToInt32(cmd.ExecuteScalar());
            conexao.desconectar();
        }