0
I need to search the database for a list where it is necessary to filter by the employee, the initial date and the final date. However, when you pass the parameters and enter while, you jump to catch
public List<Nota> BuscarNotas(int funcionarioid, DateTime dataemissaoi, DateTime dataemissaof)
{
List<Nota> oNotas = new List<Nota>();
using (MySqlConnection conexao = ConexaoBD.getInstancia().getConexao())
{
try
{
conexao.Open();
MySqlCommand comando = new MySqlCommand();
comando = conexao.CreateCommand();
comando.CommandText = @"select * from nota where DataEmissao
between DataEmissaoI = @dataemissaoi
and DataEmissaoF = @dataemissaof
and FuncionarioID = @FuncionarioID;";
comando.Parameters.AddWithValue("FuncionarioID", funcionarioid).ToString();
comando.Parameters.AddWithValue("DataEmissaoI", dataemissaoi).ToString();
comando.Parameters.AddWithValue("DataEmissaoF", dataemissaof).ToString();
MySqlDataReader reader = comando.ExecuteReader();
while (reader.Read())
{
Nota oNota = new Nota();
oNota.NotaID = Convert.ToInt32(reader["NotaID"].ToString());
oNota.FuncionarioID = Convert.ToInt32(reader["ClienteID"].ToString());
oNota.NumeroNota = reader["NumeroNota"].ToString();
oNota.DataEmissao = Convert.ToDateTime(reader["DataEmissao"].ToString());
oNota.Status = (Status)Convert.ToInt16(reader["Status"].ToString());
if ((reader["DataPagamentoFinal"] != DBNull.Value))
oNota.DataPagamentoFinal = Convert.ToDateTime(reader["DataPagamentoFinal"].ToString());
if ((reader["ValorPago"] != DBNull.Value))
oNota.ValorPago = Convert.ToDecimal(reader["ValorPago"].ToString());
if ((reader["Desconto"] != DBNull.Value))
oNota.Desconto = Convert.ToDecimal(reader["Desconto"].ToString());
oNotas.Add(oNota);
}
}
catch (MySqlException ex)
{
throw new Exception(ex.ToString());
}
finally
{
conexao.Close();
}
}
return oNotas;
}
}
Can someone help me?
in Exception has the error information, which is essential to know what is happening... it makes no sense to capture an Exception and release it again in a new Exception... and the sql syntax is wrong, in a note you have two emission dates ? initial and final ? the syntax should be
where DataEmissao
 between @dataemissaoi and @dataemissaof
– Rovann Linhalis
you should have marked the question as solved, and opened another question to a new problem, and not edit it... please do the [Tour] to understand how the community works. Obs: those
.ToString();
inParameters.AddWithValue
don’t make any sense...– Rovann Linhalis