hi,
i work on windows application and i have this code:

SqlCeDataReader rrs;
            SqlCeCommand comd = new SqlCeCommand("select CodePersonne from Table1 where DateR ='" + DateTime.Now.Date    + "';", conne);
            rrs = comd.ExecuteReader();

while running, i get this error:
The data type is not valid for the boolean operation. [ Data type (if known) = datetime,Data type (if known) = nvarchar ]
i can't find where is the mistake and i wish you can help me.

SqlCeDataReader rrs;

SqlCeCommand comd = new SqlCeCommand("select CodePersonne from Table1 where DateR='" + DateTime.Now + "'", conne);

rrs = comd.ExecuteReader();

Please post "Exception trace" or "Error messages" but do not say "It doesn't work".

Edited 6 Years Ago by __avd: n/a

>Sorry but really the same error message appear

No problem. Let me know the field type of DateR column and if possible, post ~complete~ code here.

You can also use parameterized query.

SqlCeConnection cn = new SqlCeConnection(@"Data Source=c:\test\compactdb\Database1.sdf");
            //SqlCeCommand cmd = new SqlCeCommand("select * from table1 where dater='" + DateTime.Now.ToShortDateString() + "'", cn);

            // OR  

            SqlCeCommand cmd = new SqlCeCommand("select * from table1 where dater=@p1", cn);
            cmd.Parameters.AddWithValue("@p1", DateTime.Now.ToShortDateString());

            cn.Open();
            SqlCeDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Console.WriteLine(dr[0] + " " + dr[1]);

            }
            dr.Close();
            cn.Close();

Edited 6 Years Ago by __avd: n/a

thank you. the type field of DateR is datetime and this is the full code:

private void rehabForm_Load(object sender, EventArgs e)
        {

            SqlCeConnection conne = new SqlCeConnection();
            conne.ConnectionString = @" Data source= |DataDirectory|\Database1.sdf";
            conne.Open();
            SqlCeDataAdapter da;
            DataTable dtresullt = new DataTable();
             SqlCeDataReader rrs;
            SqlCeCommand comd = new SqlCeCommand("select CodePersonne from  Table1 where DateR ='" + DateTime.Now.ToShortDateString() + "';", conne);
            rrs = comd.ExecuteReader();
            
             while (rrs.Read())
                {
                    SqlCeDataReader rs;
                    SqlCeCommand cmd = new SqlCeCommand("SELECT [Nom],[Prenom],[DateNaissance]  FROM  Table2 where CodePersonne ='" + Convert.ToInt32(rrs["CodePersonne"].ToString()) + "';", conne);
                    rs = cmd.ExecuteReader();
                    da = new SqlCeDataAdapter(cmd);
                    da.Fill(dtresullt);

                }
                dataGridView1.DataSource = dtresullt;
           

        }

thanks again

Edited 6 Years Ago by basma.lm: n/a

try this

DateTime.Now.toString("yyyyMMdd");

Edited 6 Years Ago by finito: forgot code tagging

try this
C# Syntax (Toggle Plain Text)

1.
DateTime.Now.toString("yyyyMMdd");

thank you very much, it is solved

This question has already been answered. Start a new discussion instead.