操纵DataGridView [英] manipulate DataGridView
问题描述
如果有人可以帮助(我先看看结合日期和时间)(例如:(DatetaskStart,TimetaskStart),(DatetaskEnd,TimetaskEnd))。
在整个dategridview期间,我想在获得的任务的组合((日期,时间)和任务结束的((日期,时间)之间进行减法),最后得到所有的时间(以小时为单位)获取的任务
Dim sql As String =select id_task,DatetaskStart,TimetaskStart,DatetaskEnd,TimetaskEnd from task where id_task = & Textbox1.Text&和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作为新的MySqlDataAdapter(sql,connStr)
SQLAdapter.Fil l(ds,connectString)
DataGridView1.DataSource = ds
DataGridView1.DataMember =connectString
DataGridView1.AutoResizeColumns()
connection.Close()
对于每一行作为DataGridViewRow在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))
下一个
total = Time_task
TextBox7 .Text =总
你需要这样的东西;
Dim TaskEnd As DateTime
Dim TaskStart As DateTime
Dim result As TimeSpan = TaskEnd - TaskStart
MsgBox(result.TotalHours)
VB有一个TimeSpan,当你需要跟踪一个持续时间,使用它!
请稍后,尝试不拖动任何不相关的项目。这个问题与datagridview无关...它与日期和时间有关...
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
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...
这篇关于操纵DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!