I have the following code:
public JsonResult salvaPaciente(string cns, string sexo, string dataNasc, string nome, string raca,
string cep, string ibge, string logradouro, string endereco, string numero,
string complemento, string bairro, string telefone, string email)
{
byte[] bytes = System.Text.Encoding.GetEncoding("iso-8859-8").GetBytes(nome);
nome = System.Text.Encoding.UTF8.GetString(bytes);
paciente oPaciente = new paciente()
{
bairro = bairro,
cep = cep,
cns = cns,
complemento = complemento,
dataNasc = Convert.ToDateTime(dataNasc),
email = email == "" ? " " : email,
endereco = endereco,
ibge = ibge,
logradouro = logradouro,
nacionalidade = "010",
nomePaciente = nome,
numero = numero,
raca = raca,
sexo = sexo,
telefone = telefone
};
modelOff.pacientes.Add(oPaciente);
try
{
modelOff.SaveChanges();
return Json("sim", JsonRequestBehavior.AllowGet);
}
catch
{
return Json("nao", JsonRequestBehavior.AllowGet);
}
}
It worked normally and stopped working at all with the following error:
[FormatException: String was not recognized as a valid DateTime.]
The string dataNasc
is '24 / 06/1979 '