0

我需要此代码的帮助..它已成功添加,但它不会从每个数据库记录中循环..我的数据库中有 3 条记录,但他只检测到 1 条,我使用循环..它不会循环并添加到它..对修改此代码有任何帮助吗?

我有来自字段名的 3 条记录:dtr_grantotal:

  1. = 10:41:00
  2. = 01:11:00
  3. = 03:30:10

    sqlSTR = "select * from tblTImelog where dtr_datelog Between '" & DateTimePicker1.Text & "' AND '" & DateTimePicker2.Text & "'"
    ExecuteSQLQuery(sqlSTR)
    
    _totalDays = sqlDT.Rows.Count
    
    If sqlDT.Rows.Count > 0 Then
        Dim T1 As String = "00:00:00"
        Dim myRow As DataRow = sqlDT.Rows(sqlDT.Rows.Count - 1)
        Dim span1 As TimeSpan = TimeSpan.Parse(T1)
    
        For i = 0 To sqlDT.Rows.Count - 1
            Dim span2 As TimeSpan = TimeSpan.Parse(sqlDT.Rows(i)("dtr_grandtotal"))
            t1 = span1.Add(span2).ToString
        Next 
    
        MsgBox(t1)
    End If
    

    他只从我的 msgbox 中显示第一个.. 虽然我在我的 for 循环中添加了它..

4

2 回答 2

0

t1每次都在覆盖你的。改为这样做:

For i = 0 To sqlDT.Rows.Count - 1
    Dim span2 As TimeSpan = TimeSpan.Parse(sqlDT.Rows(i)("dtr_grandtotal"))
    span1 = span1.Add(span2)
Next 

t1 = span1.ToString
MsgBox(t1)
于 2012-07-17T02:41:27.933 回答
0

用这个替换你的 For 循环:

 For i = 0 To sqlDT.Rows.Count - 1
            Dim span2 As TimeSpan = TimeSpan.Parse(sqlDt.Rows(i)("dtr_grandtotal").ToString)
            span1 = span1.Add(span2)
        Next

        MsgBox(span1.ToString)
于 2012-07-17T02:46:12.083 回答