Access query with c #

0

I'm doing an Access query in windowsForm I get an error when changing the fixed dates by dateTimePicker how can I make the date the right way, that it works p>

OleDbDataReader read = MSAConnection.read(@"
    select 
       p.cod,
       #14/3/2018# as Fecha,
       (select  count(*) 
        from Persona p 
        where not exists( select ma.codPersona 
                          from Control ma 
                          where ma.codPersona = p.codPersona 
                          and ma.fecha = #14/3/2018#)) as Total
    from Persona p 
    where not exists( select ma.codPersona 
                      from Control ma 
                      where ma.codPersona = p.codPersona 
                      and ma.fecha = #" + dateTimePicker + "#)");
        while (read.Read())
        {
            int total = Convert.ToInt32(read["Total"]);
            string a = Convert.ToString(read["cod"]);
        }
    
asked by 16.03.2018 в 17:02
source

2 answers

0
select 
   p.cod,
   #14/3/2018# as Fecha,
   (select  count(*) 
    from Persona p 
    where not exists( select ma.codPersona 
                      from Control ma 
                      where ma.codPersona = p.codPersona 
                      and ma.fecha = #14/3/2018#)) as Total
from Persona p 
where not exists( select ma.codPersona 
                  from Control ma 
                  where ma.codPersona = p.codPersona 
                  and ma.fecha = '#' + dateTimePicker + '#'));


        while (read.Read())
        {
            int total = Convert.ToInt32(read["Total"]);
            string a = Convert.ToString(read["cod"]);
        }
    
answered by 16.03.2018 в 17:18
0

What do you think?

OleDbDataReader read = MSAConnection.read(@"
    select 
       p.cod,
       #" + dateTimePickerFalta.Value.ToShortDateString() + @"# as Fecha,
       (select  count(*) 
        from Persona p 
        where not exists( select ma.codPersona 
                          from Control ma 
                          where ma.codPersona = p.codPersona 
                          and ma.fecha = #" + dateTimePickerFalta.Value.ToShortDateString() + @"#)) as Total
    from Persona p 
    where not exists( select ma.codPersona 
                      from Control ma 
                      where ma.codPersona = p.codPersona 
                      and ma.fecha = #" + dateTimePickerFalta.Value.ToShortDateString() + "#)");
        while (read.Read())
        {
            int total = Convert.ToInt32(read["Total"]);
            string a = Convert.ToString(read["cod"]);
        }
    
answered by 16.03.2018 в 17:40