【发布时间】:2020-11-26 10:19:23
【问题描述】:
我想为 FACILITIES 添加列,然后使用他们的 fac_id 从另一个表中查找他们的产水量,以在列标题下方显示为单行。
Do While tableRetrieve.Read = True
table.Columns.Add(tableRetrieve("facility"), Type.GetType("System.String"))
Dim newDate As DateTime = DateTime.ParseExact(dtpFrom.Value, "MM/dd/yyyy h:m:s tt",
System.Globalization.DateTimeFormatInfo.InvariantInfo)
Dim myDate As String = newDate.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo)
If myDate = tableRetrieve("sentDate") Then
If tableRetrieve("prod_id") = tableRetrieve("fac_id") Then
table.Rows.Add(tableRetrieve("facility_produce"))
End If
End If
Loop
我可以添加列标题,但在行中失败。
下面是输出的图像。显示列标题,但产水量仅显示在一行中。基于 prod_id 等于 fac_id 的每个对应列应该有产水量。
更新:
这就是我的代码现在的样子。如果只有一行,这很有效。如果还有另一行,则会显示错误。
Do While tableRetrieve.Read = True
table.Columns.Add(tableRetrieve("facility"), Type.GetType("System.String"))
If tableRetrieve("facility_id") = tableRetrieve("fac_id") Then
newDate = tableRetrieve("sentDate")
If prevDate = newDate Then
table.Rows(row)(col) = tableRetrieve("facility_produce")
prevDate = newDate
col += 1
Else
If row = 0 Then
col += 1
table.Rows.Add(tableRetrieve("sentDate"))
table.Rows(row)(col) = tableRetrieve("facility_produce")
prevDate = newDate
col += 1
Else
col = 0
row += 1
table.Rows.Add(tableRetrieve("sentDate"))
table.Rows(row)(col) = tableRetrieve("facility_produce")
col += 1
End If
End If
End If
Loop
dgvFacility.DataSource = table
【问题讨论】:
标签: mysql vb.net datatable datagridview inner-join