-1
I made a business rule where I pass some information from my service order to my cashier. However when I will perform the search in the box, my date passes 01/01/0001, and the error of characters.
Public List<Model.caixa> Select()
{
List<Model.caixa> ListaCaixa = new List<Model.caixa>();
SqlConnection conexao = new SqlConnection(strCon);
string sql = "Select * from caixa;";
SqlCommand cmd = new SqlCommand(sql, conexao);
conexao.Open();
try
{
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
Model.caixa caixa = new Model.caixa();
caixa.CodCaixa = Convert.ToInt32(reader[0].ToString());
caixa.CodSrv = Convert.ToInt32(reader["CodSrv"].ToString());
caixa.TipoSrv = reader["TipoSrv"].ToString();
**caixa.DataPagamento = Convert.ToDateTime(reader["DataPagamento"].ToString());**
caixa.Status = reader["Status"].ToString();
caixa.Parcelamento = reader["Parcelamento"].ToString();
caixa.Pagamento = reader["Pagamento"].ToString();
ListaCaixa.Add(caixa);
}
}
catch
{
MessageBox.Show("Deu erro na seleção do caixa!");
}
finally
{
conexao.Close();
}
return ListaCaixa;
}
When it comes caixa.DataPagamento = Convert.ToDateTime(reader["DataPagamento"].ToString());
already falls for catch
.
If anyone can help, I’d be grateful!
the first reading in the bank worked, but in the other already enters the catch.
– TMBruhTH
What is the Exception that is giving? inserts in front of the catch this:
(Exception ex)
and take what’s in the ex property. Message– Tiago S
ex. Message "String not recognized as valid Datetime." string - this one
– TMBruhTH
The problem is in formatting your date string in the database, you can see which format is in the database?
– Tiago S
put Datetime
– TMBruhTH
Take a text from the Datapayment column so I can test with the saved format
– Tiago S
Preferably what’s going wrong
– Tiago S
a question, where I get this text for you? I am in debug with it, if you tell me the place already send
– TMBruhTH
In the debug, select
reader["DataPagamento"]
and right-click and select the optionAdd Watch
– Tiago S
Or else you see right in the comic
– Tiago S
Reader["Datapayment"] error CS0103: The name 'Reader' does not exist in the Current context
– TMBruhTH
was this error message that appeared
– TMBruhTH
You will need to put a pause break in it and have search there will work
– Tiago S
All right, I’ll do it tomorrow I’ll tell you the result hugs
– TMBruhTH