Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite
estou estudando C# e na procura de tutoriais referente aos CRUDS - não achei nenhum que utilizasse o maskedTextbox com mascara __/__/____ formato dd/MM/yyyy e no meu banco de dados MYSQL o campo nascto e nascto do conjugue esta como date.
porem se eu utilizar como string no banco de dados a inclusão funciona normalmente, mas se deixar como date da erro. acho que deva ser alguma formatação da data no código,
alguem poderia verificar o codigo e me apontar onde estou errando, alterando o codigo para a solução correta ?
private void btnIncluir_Click(object sender, EventArgs e)
{
if ((txtEleitor.Text != string.Empty))
{
cmdConsultar = new MySqlCommand("select eleitor from tbeleitor where eleitor='" + txtEleitor.Text + "'", dbConexao);
MySqlDataReader retconsulta = cmdConsultar.ExecuteReader();
if (retconsulta.HasRows)MessageBox.Show("Este Eleitor j existe", "Mensagem do Sistema");
}retconsulta.Close();
MySqlConnection cn2 = new MySqlConnection(Banco);
cn2.Open();
string incluiSql = "insert into tbeleitor(eleitor,nascto, estadocivil, titulo, zona, secao, conjugue, nasctoconjugue, filhos, qtderes, telefone, celular, cep, tipo, rua, num, compl, bairro, cidade, uf, lider, origem, regiao,filiado, partido, email, recebemala, obs) values ('" +new MySqlCommand(incluiSql, cn2);
cmdIncluir.ExecuteNonQuery();
MessageBox.Show("Inclusao efetuada com sucesso!", "Mensagem do Sistema");
}
limpar();
retconsulta.Close();
travaJanelas();
atualizaGrid();true;
tbcDadosEleitor.SelectedTab = tbcDadosEleitor.TabPages[0];
txtEleitor.Focus();
}MessageBox.Show("Obrigatrio o preenchimento dos campos", "Mensagem de Alerta");
txtEleitor.Focus();
}
}int.Parse(e.RowIndex.ToString());
if (linhaClick != -1)txtEleitor.Text = dtgEleitor[1, linhaClick].Value.ToString();
mtbDataNasctoEleitor.Text = dtgEleitor[2, linhaClick].Value.ToString();
cbxEstadoCivil.Text = dtgEleitor[3, linhaClick].Value.ToString();
txtTitulo.Text = dtgEleitor[4, linhaClick].Value.ToString();
cbxZonaEleitoral.Text = dtgEleitor[5, linhaClick].Value.ToString();
cbxSecaoEleitoral.Text = dtgEleitor[6, linhaClick].Value.ToString();
txtConjugue.Text = dtgEleitor[7, linhaClick].Value.ToString();
mtbDataNasctoConjugue.Text = dtgEleitor[8, linhaClick].Value.ToString();
cbxFilhos.Text = dtgEleitor[9, linhaClick].Value.ToString();
cbxQtdeResidencia.Text = dtgEleitor[10, linhaClick].Value.ToString();
mtbTelefoneEleitor.Text = dtgEleitor[11, linhaClick].Value.ToString();
mtbCelularEleitor.Text = dtgEleitor[12, linhaClick].Value.ToString();
mtbCepEleitor.Text = dtgEleitor[13, linhaClick].Value.ToString();
txtTipoLogradouro.Text = dtgEleitor[14, linhaClick].Value.ToString();
txtLogradouroEleitor.Text = dtgEleitor[15, linhaClick].Value.ToString();
txtNumResEleitor.Text = dtgEleitor[16, linhaClick].Value.ToString();
txtComplementoEnderecoEleitor.Text = dtgEleitor[17, linhaClick].Value.ToString();
txtBairroEleitor.Text = dtgEleitor[18, linhaClick].Value.ToString();
txtCidadeEleitor.Text = dtgEleitor[19, linhaClick].Value.ToString();
txtEstadoEleitor.Text = dtgEleitor[20, linhaClick].Value.ToString();
cbxLider.Text = dtgEleitor[21, linhaClick].Value.ToString();
cbxOrigem.Text = dtgEleitor[22, linhaClick].Value.ToString();
cbxRegiaoEleitor.Text = dtgEleitor[23, linhaClick].Value.ToString();
cbxFiliacaoPartidoEleitor.Text = dtgEleitor[24, linhaClick].Value.ToString();
cbxPartidoPoliticoEleitor.Text = dtgEleitor[25, linhaClick].Value.ToString();
txtEmailEleitor.Text = dtgEleitor[26, linhaClick].Value.ToString();
cbxRecebeMalaDireta.Text = dtgEleitor[27, linhaClick].Value.ToString();
rtbObservacao.Text = dtgEleitor[28, linhaClick].Value.ToString();
}
}Carregando comentários...