C# Datagridview

Jan 12 2012 1:51 AM
Hi, need to convert seconds to hh:mm:ss in c# datagridview from seconds column to duration column, below is requirement, kindly help me on this

Name Seconds Duration
 Customer1 call 40 00:00:40
 customer2 call 90640 25:10:40
 customer3 call 1201 00:20:01
 customer4 call 25 00:00:25

Below is the code...

DataSet ds = new DataSet();
  SqlDataAdapter da = new SqlDataAdapter();
  SqlCommand slctVendors = new SqlCommand("SELECT TRUSTID as 'TRUSTS', COUNT(JOBIDST)as 'JOBS', " +
  "CONVERT(char(8),DATEADD(second, sum(PLAYTIME),'00:00:00'), 108) " +
  " as 'DURATION', SUM(PLAYTIME) " +
  "FROM DCLIVEJOBS where PSTATUS < '95' GROUP BY TRUSTID", cn);
  da.SelectCommand = slctVendors;
  da.Fill(ds, "tblDclivejobs");
  dgViewJobs.DataSource = ds.Tables["tblDclivejobs"];
  int sum = 0;
 
  for (int i = 0; i < dgViewJobs.Rows.Count; ++i)
  {
  sum += Convert.ToInt32(dgViewJobs.Rows[i].Cells[1].Value);
  //sum += Convert.ToInt32(dgViewJobs.Rows[i].Cells[3].Value);
  //count = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
  }
  int sum1 = 0;
  for (int j = 0; j < dgViewJobs.Rows.Count; ++j)
  {
  sum1 += Convert.ToInt32(dgViewJobs.Rows[j].Cells[3].Value);
  //count = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
  }
 
  int x = dgViewJobs.Rows.Count;
  dgViewJobs.Rows[x - 1].Cells[0].Value = "Total".ToString();
  dgViewJobs.Rows[x - 1].Cells[1].Value = label5.Text = sum.ToString();
  dgViewJobs.Rows[x - 1].Cells[3].Value = label6.Text = sum1.ToString();
 
  label5.Text = sum.ToString();
  label6.Text = sum1.ToString();
  int secs = Convert.ToInt32(label6.Text);
  string du = string.Format("{0:00}:{1:00}:{2:00}",secs/3600,(secs/60)%60,secs%60);
  label7.Text = du;
  dgViewJobs.Rows[x - 1].Cells[2].Value = label7.Text;
  cn.Close();
  this.dgViewJobs.Columns[3].Visible = false;
  dgViewJobs.ClearSelection();
  foreach (DataGridViewColumn cl in dgViewJobs.Columns)
  {
  cl.SortMode = DataGridViewColumnSortMode.NotSortable;
  }

Answers (3)