1
I’m trying to convert a string q I pull from the database with the instruction
DateTime PrevisaoDataInicio = DateTime.Parse(reader["PrevisaoDataInicio"].ToString())
And makes the following mistake:
Character string not recognized as valid datetime.
The entire method being used is below:
private List<EntendimentoDominio> TransformaReaderEmListaDeObjeto(SqlCeDataReader reader)
{
var entendimentos = new List<EntendimentoDominio>();
while (reader.Read())
{
var temObjeto = new EntendimentoDominio()
{
CodEntendimento = int.Parse(reader["CodEntendimento"].ToString()),
AreaResponsavel = reader["AreaResponsavel"].ToString(),
Modulo = reader["Modulo"].ToString(),
Projeto = reader["Projeto"].ToString(),
Subprojeto = reader["Subprojeto"].ToString(),
DescricaoResumida = reader["DescricaoResumida"].ToString(),
DescricaoDetalhada = reader["DescricaoDetalhada"].ToString(),
CustoEstimado = reader["CustoEstimado"].ToString(),
NomeDocumentoAnexo = reader["NomeDocumentoAnexo"].ToString(),
CaminhoDocumentoAnexo = reader["CaminhoDocumentoAnexo"].ToString(),
Status = reader["Status"].ToString(),
TempoEstimado = reader["TempoEstimado"].ToString(),
PrevisaoDataInicio = DateTime.Parse(reader["PrevisaoDataInicio"].ToString()),
PrevisaoDataFinal = DateTime.Parse(reader["PrevisaoDataFinal"].ToString())
};
entendimentos.Add(temObjeto);
}
reader.Close();
return entendimentos;
}
The
reader["PrevisaoDataInicio"]
is receiving what?– CesarMiguel
What type of column
PrevisaoDataInicio
in the database?– dcastro
my friend, before converting the string into Datetime, I recommend that you use a variable to receive its value, put a breakpoint in the created line, make a test and show us what such a variable is bringing.
– Jedaias Rodrigues
The type of the Preview column is datetime also in the database.
– Italo