-1
 string connectionString = ConfigurationManager.ConnectionStrings["payroll_conn"].ConnectionString;
        using (SqlConnection sqlconn = new SqlConnection(connectionString))
        {
            sqlconn.Open();
            using (SqlCommand com = new SqlCommand("SELECT * FROM employee WHERE fname=@fname and designation=@designation", sqlconn))
            {
                com.Parameters.AddWithValue("@fname", en1.Text);
                com.Parameters.AddWithValue("@designation", e1.Text);

                using (SqlDataAdapter sda = new SqlDataAdapter(com))
                {

                    ds1 = new DataSet();
                    sda.Fill(ds1);
                }
                try
                {
                    label39.Text = ds1.Tables[0].Rows[i]["id"].ToString();

                    dateTimePicker1.Text = ds1.Tables[0].Rows[i]["enddate"].ToString();


                }
                catch (Exception ex)
                {

                    Console.WriteLine(ex.Message);
                }
            }
        }

how can I add one day to the dateTimePicker1 after I selected from the database I'm missing something but I don't remember it what should I do sorry if my question is a bad question

ahmed_eltot93
  • 118
  • 16

1 Answers1

1

You can parse enddate and use AddDays method.

var endate = ds1.Tables[0].Rows[i]["enddate"].ToString();
var endateplus1day = DateTime.Parse(enddate).AddDays(1);
dateTimePicker1.Text = endateplus1day.ToString();
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
  • 1
    I would guess/hope that that enddate column is already of type DateTime, so you can cast that. No ToString+Parse needed – Hans Kesting Jun 16 '19 at 12:29