I am trying to insert into MySQL database the date of birth of the user, in C # the attribute date_match is of type DateTime
and in MySQL the attribute date_match is of type Date
, to insert C # I am doing doing so:
DateTime nascimento = Convert.ToDateTime(txNascimento.Text);
bDep.Data_nascimento = nascimento;
Obs :. bDep
is the base class of the dependent
And in the dependent data class I'm inserting like this:
public void insertDependente (BDependente bDep) {
string sql = "INSERT INTO dependente(id_funcionario, nome, grau_parentesco, data_nascimento) ";
sql += "VALUES ("+bDep.Funcionario.Id_funcionario+", '"+bDep.Nome+"', '"+bDep.Grau_parentesco+"', '"+bDep.Data_nascimento+"')";
conn.update(sql);
}
I'm selecting like this:
string sql = "SELECT id_dependente, id_funcionario, nome, grau_parentesco, data_nascimento ";
sql += "FROM dependente";
while (mdr.Read()) {
BDependente bDepe = new BDependente();
bDepe.Id_dependente = mdr.GetInt16("id_dependente");
bDepe.Funcionario.Id_funcionario = mdr.GetInt16("id_funcionario");
bDepe.Nome = mdr.GetString("nome");
bDepe.Grau_parentesco = mdr.GetString("grau_parentesco");
bDepe.Data_nascimento = mdr.GetDateTime("data_nascimento");
lDep.Add(bDepe);
}
Whenever I register a new dependent on the database it looks like this:
ThefirstrecordwasmadeinMySQLitself,andeventhenwhenIlookinC#itbringsthetimeandwhenIlookinC#theotherdependent,thisothererrorappears: