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;
}
}