manipulate DataGridView

为君一笑 提交于 2019-12-25 12:51:14

问题


please if someone can help :( ,I'm looking at first to combine date and times (ex: ( DatetaskStart ,TimetaskStart) , (DatetaskEnd ,TimetaskEnd)).

And throughout my dategridview I want make a subtraction between combinaision obtained ((date, time) of the beginning of the task ) and ((date,time) of end the task) and finally get the total times in hours of all the tasks obtained.

 Dim sql As String = "select id_task, DatetaskStart ,TimetaskStart , DatetaskEnd ,TimetaskEnd from task where id_task = " & Textbox1.Text & " and  Datetask  Between '" & DateTimePicker1.Text & "' And '" & DateTimePicker2.Text & "';"
    command.CommandText = sql
    Dim Time_task as Double
    Dim total as Double
     Dim DateValue As Date
    Dim DateValue2 As Date
    connection.Open()
    Dim ds As New DataSet
    Dim SQLAdapter As New MySqlDataAdapter(sql, connStr)
    SQLAdapter.Fill(ds, "connectString")
    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "connectString"
    DataGridView1.AutoResizeColumns()
    connection.Close()


 For Each row As DataGridViewRow In DataGridView1.Rows
            Time_task += (Date.TryParse(row.Cells(3).Value + " " + row.Cells(4).Value, DateValue)) - (Date.TryParse(row.Cells(1).Value + " " + row.Cells(2).Value, DateValue2))
        Next
        total = Time_task
        TextBox7.Text = total

回答1:


You need something like this;

    Dim TaskEnd As DateTime
    Dim TaskStart As DateTime
    Dim result As TimeSpan = TaskEnd - TaskStart
    MsgBox(result.TotalHours)

VB has a TimeSpan, when every you need to keep track of a duration, use it!

Please next time, try not to drag in any unrelated items. This problem has nothing to do with a datagridview... It has to do with date and time...



来源:https://stackoverflow.com/questions/18078278/manipulate-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!