2
I intend to select by the current date, like: list all the data that was registered today in my table, I did this way and does not result in anything, does not generate errors or list any of the registered information.
//Método Listar registos cadastrado Actualmente
public List<View_Caixa> Listar_Data()
{
List<View_Caixa> lis = new List<View_Caixa>();
SqlConnection conexao = new SqlConnection(caminho);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conexao;
cmd.CommandType = CommandType.Text;
string li = "select *from view_caixa where data_registo=@data_registo"; //É aqui onde eu faço o meu select
cmd.CommandText = li;
cmd.Parameters.AddWithValue("data_registo", DateTime.Now);
conexao.Close();
SqlDataReader dr;
conexao.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
View_Caixa obj = new View_Caixa();
obj.id_caixa = Convert.ToInt32(dr["id_caixa"].ToString());
obj.funcionario = dr["funcionario"].ToString();
obj.caixa_inicial = Convert.ToDecimal(dr["caixa_inicial"].ToString());
obj.total_veda_caixa = Convert.ToDecimal(dr["total_veda_caixa"].ToString());
obj.total_venda_multicaixa = Convert.ToDecimal(dr["total_venda_multicaixa"].ToString());
obj.total_multipagamento = Convert.ToDecimal(dr["total_multipagamento"].ToString());
obj.caixa_final = Convert.ToDecimal(dr["caixa_final"].ToString());
obj.conciliacao = Convert.ToDecimal(dr["conciliacao"].ToString());
obj.data_registo = Convert.ToDateTime(dr["data_registo"].ToString());
lis.Add(obj);
}
return lis;
}
@What is the database?
– George Wurthmann
How the date is recorded in the bank?
– novic
I am using SQL-Server, I am writing this way taking the date automatically : cmd.Parameters.Addwithvalue("data_register", Datetime.Now);
– António Mateta