我有一个包含两列(日期,目标)的excel表。我需要根据今天的周数拉出目标数字并将其绑定到datagridview中的第一行。我可以用下面的代码拉出数字,但绑定它不起作用。它只是添加一个新的空列。任何想法为什么?赞赏。
Private Sub bindit()
Using cn As New OleDbConnection With {.ConnectionString = String.Format(ConnectionNoHeader, FileName)}
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(
<Text>
SELECT
date,
objectives
FROM [<%= Sheetname %>$]
</Text>.Value, cn)
dt1.Load(cmd.ExecuteReader)
dt1.AcceptChanges()
End Using
Currentweek = MyCalendar.GetWeekOfYear(
Now,
CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Sunday
)
For Each row As DataRow In dt1.Rows
If IsDBNull(row.Item("objectives")) Then
row.SetField(Of Double)("objectives", 0)
Value = MyCalendar.GetWeekOfYear(row.Field(Of DateTime)("date"),
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday)
Value1 = MyCalendar.GetYear(row.Field(Of DateTime)("date"))
Console.WriteLine("Date: {0} Week: {1} Year: {2} Objectives: {3}",
row.Field(Of DateTime)("date"),
Value, Value1,
row.Field(Of Double)("objectives")
)
End If
Next
Currentyear = MyCalendar.GetYear(Now)
ThisWeekTotal = (
From Row In dt1.AsEnumerable
Where MyCalendar.GetWeekOfYear(Row.Field(Of DateTime)("date"),
CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Sunday) = Currentweek And MyCalendar.GetYear(Row.Field(Of DateTime)("date")) = Currentyear
Select Row.Field(Of Double)("objectives")
)
bsData.DataSource = ThisWeekTotal.ToList()
DataGridView1.DataSource = bsData
End Sub