hi guys i need help with date time picker.What i am trying to do is to select data from table according to teh date selected by the user .My code looks like this but it doesnt work, it doesnt pull anything, can anyone help me with where am i going wrong.
Thanks

private void dateTimePicker1_ValueChanged_1(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection(@"Server=208.124.179.197;Database=RTLUser;UID=sa;");
            cn.Open();
            string myString = "";
            SqlDataAdapter dtadp = new SqlDataAdapter();
            DataTable dtbl = new DataTable();
            myString = @"Select word from wordTbl where date = @date";
           SqlCommand cmd = new SqlCommand(myString, cn);
            cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = dateTimePicker1.Value;
            DataSet data = new DataSet();
            SqlDataReader rdr = cmd.ExecuteReader();

            bool iftrue = false;

            while (rdr.Read())
            {
                if (rdr[0] == (dateTimePicker1))
                {
                    iftrue = true;
                }
            }
            if (iftrue == true)
            {
                cmd = new SqlCommand("SELECT word from wordTbl where date ='" + dateTimePicker1 + "'");

                rdr = cmd.ExecuteReader();
                cn.Close();
                dtadp.SelectCommand = cmd;
                dtadp.Fill(dtbl);
                dataGridView2.DataSource = dtbl;


            }
        }

Your SELECT statement only requests the word field.
This code if (rdr[0] == (dateTimePicker1)) compares the returned word field value with a DataTimePicker object (not even its value).
You need to review your code.

I would also recommend changing the code that sets the parameter value to use the date part only; assuming that is all your DB contains.

cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = dateTimePicker1.Value.Date; //<-- use DateTime.Date

Or change the SELECT comand to use a range (e.g. selected date +/- 1 day).

commented: Nice explanation. +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.