Análise de Código
Salve Galera!!!
Tô começando agora no VS2005 usando C#.
Tenho um código aqui que está funcional, mas acho que pode ser melhorado. Por exemplo a forma de fazer conexão com o banco.
eu fiz a conexão no clique do botão. Há uma forma melhor e mais coerente de se fazer isso?
Vejam o código:
private void button1_Click(object sender, EventArgs e) { OleDbConnection conexao = new OleDbConnection(strConn); conexao.Open(); if (txtImposto.Checked) { Imposto = "YES"; } SqlInsert = "INSERT INTO TB_MOVIMENTACOES (MOV_DATA,MOV_VALOR,MOV_IMPOSTO"; SqlInsert += ",MOV_DESCRICAO,MOV_FORMAPG) VALUES ("; SqlInsert += "#"+DataHoje+"#,"; SqlInsert += "'"+txtValorServico.Text+"',"; SqlInsert += ""+Imposto+","; SqlInsert += "'"+txtDescricao.Text+"',"; SqlInsert += "'"+txtPagamento.Text+"'"; SqlInsert += ")"; OleDbCommand Rs = conexao.CreateCommand(); Rs.CommandText = SqlInsert; Rs.ExecuteNonQuery(); txtDescricao.Text = ""; txtImposto.Checked = false; txtPagamento.Text = ""; txtValorServico.Text = ""; MessageBox.Show("Dados Gravados Com Sucesso!"); }
Discussão (4)
Carregando comentários...