Skip to content

Monther calander value from database

ta mu

Asked Sep 15, 2013, 3:29 AM EDT2 answers
Share
LinkedInX
i am using this code to get stored values of different controls from database. others are ok but monthcalander and datatime picker dont get values from database. i inserted these values using


SqlCommand cmd = new SqlCommand   ("INSERT INTO reminder (message,date,time)     VALUES ('" + textBox1.Text + "','" + monthCalendar1.SelectionStart + "','" + dateTimePicker1.Value + "')", my);

and try to get with this code. no error but why not both controls getting there values.


my.Open();
            string cellvalue = dataGridView1["id", index].Value.ToString();

            SqlCommand cmd = new SqlCommand("SELECT * FROM reminder WHERE id='" + cellvalue + "'", my);
            SqlDataReader rd = cmd.ExecuteReader();
            rd.Read();
            upr.textBox1.Text = rd["message"].ToString();
       
            upr.monthCalendar1.SelectionStart =System.Convert.ToDateTime(rd["date"]);
            upr.label1.Text = rd["id"].ToString();
            upr.dateTimePicker1.Value = System.Convert.ToDateTime(rd["date"]);
            my.Close();

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi ta mu,

    please make sure if rd["date"] has value.


    0
  • 1 short reply
    • 0
      yes its value exists
      0