public void atualizarTrans(CadastroTrans a) { if (conn.State == ConnectionState.Open) { SqlCommand cmd = new SqlCommand("UPDATE Transacao SET Valor=@1, DataTrans=@2, Origem=@3, TipoMoeda=@4, Destino=@5 where idTransacao=@0", conn); cmd.Parameters.AddWithValue("@1", a.getValor()); cmd.Parameters.Add("@2", SqlDbType.Date, 90).Value = a.getdataTrans(); cmd.Parameters.AddWithValue("@3", a.getidOrigem()); cmd.Parameters.AddWithValue("@4", a.getidMoeda()); cmd.Parameters.AddWithValue("@5", a.getidDestino()); cmd.Parameters.AddWithValue("@0", a.getId()); cmd.CommandType = CommandType.Text; //conn.Open(); try { int i = cmd.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Registro atualizado com sucesso!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { conn.Close(); } } }
public void listarTable() { for (int i = 0; i < grdUsu.RowCount; i++) { grdUsu.Rows[i].DataGridView.Rows.Clear(); } // Pega os Id da tabela do banco de dados int count = TransacaoDAO.quantidade(); int aa = 0; for (int i = 0; i <= count; i++) { if (!(TransacaoDAO.listarUsu(i) == null)) { CadastroTrans a = TransacaoDAO.listarUsu(i); grdUsu.Rows.Add(); grdUsu.Rows[aa].Cells[0].Value = a.getId(); grdUsu.Rows[aa].Cells[1].Value = a.getValor(); grdUsu.Rows[aa].Cells[2].Value = a.getdataTrans(); grdUsu.Rows[aa].Cells[3].Value = a.getOrigem(); grdUsu.Rows[aa].Cells[4].Value = a.getMoeda(); grdUsu.Rows[aa].Cells[5].Value = a.getDestino(); aa++; } } listarMoedas(); listarOrigem(); listarDestino(); }