嗨,我如何在新列中显示计算的超时和时间
假设我的数据网格视图中有此列数据:
Emplyee ID | EmployeeName | Date | TimeIN | TimeOut
0 | Danilo | 2013-06-06 | 08:00 | 15:00
然后我想显示这样的结果:
Emplyee ID | EmployeeName | Date | TimeIN | TimeOut | TOTAL
0 | Danilo | 2013-06-06 | 08:00 | 15:00 | 7:00
我试过这个代码:
Dim sDateFrom As TimeSpan
Dim sDateTo As TimeSpan
Dim timeDiff As TimeSpan
For i As Integer = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(i).Cells(3).Value = lblholdname.Text Then
sDateFrom = DataGridView1.Rows(i).Cells(3).Value
sDateTo = DataGridView1.Rows(i).Cells(4).Value
timeDiff = sDateTo - sDateFrom
'this code is not right i want column instead of row but its not accepting timespan
DataGridView1.Rows(i).Cells(5).Value = timeDiff
'i try using this too
'DataGridView1.Columns.Add("TOTAL", "TOTAL") = timeDiff
End If
Next
好的,所以我设法得到了我需要的东西,但是出现了一个新问题,而不是显示 1 列,而是显示 2 列,我的表现在看起来像这样
Emplyee ID | EmployeeName | Date | TimeIN | TimeOut | TOTAL | TOTAL
0 | Danilo | 2013-06-06 | 08:00 | 15:00 | 7:00 |
我添加此代码以获得该结果:
DataGridView1.Columns.Add("TOTAL", "TOTAL")
DataGridView1.Rows(i).Cells(6).Value = timeDiff
好的,这就是我在数据库中使用 DATA 填充 DGV 的方式:
con = New MySqlConnection
con.ConnectionString = "server=localhost;username=root;password=nhhs;port=3306;database=employeedb"
con.Open()
cmd = New MySqlCommand("select e.employeeID, e.employeefname, e.employeelname, t.dateoftime, t.timein,t.timeout from tblemployee as e, tbltimepunch as t where e.employeelname = '" & lblholdlastname.Text & _
"' and e.employeeID = t.employeeID and dateoftime between '" & MonthCalendar1.SelectionStart.ToString("yyyy-MM-dd") & _
"' and '" & MonthCalendar1.SelectionEnd.ToString("yyyy-MM-dd") & "'", con)
da = New MySqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
With DataGridView1
.Columns(0).DataPropertyName = "employeeID"
.Columns(1).DataPropertyName = "employeefname"
.Columns(2).DataPropertyName = "employeelname"
.Columns(3).DataPropertyName = "dateoftime"
.Columns(4).DataPropertyName = "timein"
.Columns(5).DataPropertyName = "timeout"
.DataSource = dt
End With
con.Close()