title: inserting date value in sql server and retrieving it into textbox using c#
body: <p>i am trying to insert date value from datetimepicker into sql server database  and retrieve it into a textbox using select command.i am using c# as frontend language.please fix this for me.
  here is the code i have written.</p>
  
  <pre><code> private void save_Click(object sender, EventArgs e)
      {
          try
          {
  
              SqlCommand cmd = new SqlCommand("insert into xt1 values('" + textBox1.Text + "'," + int.Parse(textBox2.Text) + ")", cnn);
              cnn.Open();
              cmd.ExecuteNonQuery();
              MessageBox.Show("saved");
              cnn.Close();
  
          }
          catch (Exception x)
          { 
              MessageBox.Show(x.Message);
              cnn.Close();
  
          }
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          this.Dispose();
      }
  
      private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
      {
          dateTimePicker1.Text = DateTime.Now.ToShortDateString();
          textBox1.Text = dateTimePicker1.Text;
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          try
          {
              cnn.Open();
              SqlCommand  ad = new SqlCommand ("select * from xt1 where id=" + int.Parse(textBox2.Text), cnn);
              SqlDataReader dr = ad.ExecuteReader();
              dr.Read();
              while (dr.HasRows)
              {
                  textBox1.Text = dr[0].ToString();
                  textBox2.Text = DateTime .Parse ( dr[1].ToString());
              }
  
              cnn.Close();
          }
          catch (Exception x)
          {
              MessageBox.Show(x.Message);
          }
  </code></pre>
  
  <p>insertion into database is successfull but retrieval is the nightmare to me..</p>