0

Hi every one!

I have an acces table viewed in datagridview and trying to add the values of column 3 and 4 (date time data types). my code is as below.

string StartTime = dataGridView1.Rows[i].Cells[3].Value.ToString();
string StartTime = dataGridView1.Rows[i].Cells[3].Value.ToString();
                 string Total = dataGridView1.Rows[i].Cells.Value.ToString();
                 MessageBox.Show(StartTime);
                 TimeSpan spantotal = TimeSpan.Parse(Total); //convert f into timespan and store in a
                 TimeSpan spanStartTime = TimeSpan.Parse(StartTime);
                 TimeSpan SpanEndTime = (spantotal.Add(spanStartTime));// sum of timespan a and b store in c
                 TimeEnd = new DateTime(SpanEndTime.Ticks);
                 string strTimeEnd = TimeEnd.ToString("hh:mm tt");
                 dataGridView1.Rows[i].Cells[4].Value = strTimeEnd;   //assign c to to.value]

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ddanbe
0

What exactly is your problem?
Do you know DateTime has an Add method and that the + operator can be used to perform additions of DateTime and TimeSpan?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.