0
I was having trouble Cast when running a lambda and serializing for the service. Well, the solution was to pass everything to String and I got it. On the other side(Android App) I pick up and do what has to be done. Well, it turns out that this customer has his dates loaded into the bank like a float, like this one(79018). Turns out when I give one float.Parse(data_string)
and then a Convert.ToDateTime(floatvalue)
, gives the casting error saying that can not do the cast of Double for Single. If I put for single, the error continues, the same problem I was having before, which generated me some posts here. How I transform this value into Datetime?
private void listaLibera_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var libera = e.SelectedItem as Liberacao;
DateTime datas = Convert.ToDateTime(float.Parse(libera.DataLib));
lblTipoVenda.Text = "Tipo de Venda: " + libera.TipoVenda;
//lblVencimento.Text = "Vencimento: " + (Convert.ToDateTime(libera.Vendedor)).ToString("dd/mm/yyyy");
lblJuros.Text = "Juros: " + libera.Juros.ToString();
lblEntrada.Text = "Entrada: " + libera.Entrada;
lblAcrescimo.Text = "Acréscimo: " + libera.Acrescimo;
lblDesconto.Text = "Desconto: " + datas.ToString("dd/mm/yyyy");
}
I took the literal value and tried to convert and continues the error of cast, thus: Convert.ToDateTime(79018.0f)
.
You need to see the code, the means to reproduce the problem. I don’t think I’ve ever seen a database as badly structured as this one. I’ve seen one before that the columns were all bad words that caused less trouble than this.
– Maniero
I have been having this Cast problem for a long time. I had to do a Ambi to continue my work. Whenever I loaded a float or double value of the bank and when I assigned the property in my DTO, I gave this error and did not solve it. What I did was pass everything to string and so I could continue, but it’s not what I wish, but I had to do so
– pnet
Their system was developed in Clarion and I think that’s why it’s in numerical form and not in date format and has been around for over 15 years.
– pnet
I can’t do that inside the Xamarin.Forms:
var datas = DateTime.FromOADate(meu_double)
. Does not recognize the Fromoadate– pnet
Is this date not in millisecond format? If so, try var time = Timespan.Frommilliseconds(milliseconds);
– Grupo CDS Informática
@Grupocdsinformática, I can’t say, but if you do it in the comic book:
convert(datetime, 79018-36163) as DataLib
I get it:2017-05-02 00:00:00.000
. 79018 is equivalent to the fieldDataLib
– pnet
@pnet looks that gist, it explains why of the calculation. I think the way will be more or less this. I will put a code as answer to see if it helps.
– Grupo CDS Informática