DA.update行为不一致 [英] Inconsistent DA.update behavior
问题描述
我有一个没有按预期更新的顽固表。如果我在DGV中的许多行中更改了许多列,则更新似乎会更新所有内容但是我更改的最后一列/行。如果我更改日期列以计算持续时间列,则表
将按预期更新。如果我更改DGV中的一个字符串列,则更新时不会发生任何事情。当没有错误并且得到混合结果时很难调试。
I have a stubborn table that is not updating as expected. If I change many columns in many rows in the DGV the update seems to update everything BUT the last column/row that I changed. If I change the date columns to calculate the duration columns the table updates as expected. If I change one string column in the DGV nothing happens on update. Kind of hard to debug when there are no errors and getting mixed results.
我可以在这个过程中使用新鲜的眼球。
I could use from fresh eyeballs on this procedure.
Private Sub GetHours() ''---------------------------------------------------------------------------------GetHours
If Not DSet.Tables.Contains("TimeLogTable") Then
DSet.Tables.Add("TimeLogTable")
Else
DSet.Tables("TimeLogTable").Rows.Clear()
End If
Using SQLConn As New SqlConnection(My.Settings.SQLConn)
Using TimeLogDA As New SqlDataAdapter("SELECT * FROM timelog WHERE UserName ='" & Username & "'" &
" AND cast(PaidTimeIn as date) >='" & ShiftPrdStart & "'" &
" AND Cast(PaidTimeOut as date) <='" & ShiftPrdEnd & "' ORDER BY ActualTimeIn Desc", SQLConn)
TimeLogDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
TimeLogDA.FillSchema(DSet.Tables("TimeLogTable"), SchemaType.Source)
TimeLogDA.Fill(DSet.Tables("TimeLogTable"))
TimeLogBS.DataSource = DSet.Tables("TimeLogTable")
DGV_Hours.DataSource = TimeLogBS
BindNav_TimeLog.BindingSource = TimeLogBS
For Each TimeLogRow As DataRow In DSet.Tables("TimeLogTable").Rows
TimeLogRow("DayName") = CDate(TimeLogRow("ActualTimeIn").ToString).ToString("dddd")
Next
With DGV_Hours
.Columns("ActualHours").ReadOnly = True
.Columns("PaidHours").ReadOnly = True
.Columns("DayName").ReadOnly = True
End With
For Each TimeLogCol As DataGridViewColumn In DGV_Hours.Columns
If Not TimeLogCol.ValueType = GetType(DateTime) Then
TimeLogCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
Else
TimeLogCol.Width = 130
End If
Next
End Using
End Using
End Sub ''------------------------------------------------------------------------------------------------GetHours
Private Sub Button_UpdateTimeLog_Click(sender As Object, e As EventArgs) Handles Button_UpdateTimeLog.Click ''Update Timelog
Using SQLConn As New SqlConnection(My.Settings.SQLConn)
Using TimeLogDA As New SqlDataAdapter("SELECT * FROM timelog WHERE UserName ='" & Username & "'" &
" AND cast(PaidTimeIn as date) >='" & ShiftPrdStart & "'" &
" AND Cast(PaidTimeOut as date) <='" & ShiftPrdEnd & "' ORDER BY ActualTimeIn Desc", SQLConn)
Dim TimeLogCB As New SqlCommandBuilder(TimeLogDA)
TimeLogBS.EndEdit()
TimeLogDA.Update(DSet.Tables("TimeLogTable"))
End Using
End Using
End Sub ''----------------------------------------------------------------------------------------------------Update Timelog
生活就像你今天要死了一样,学会好像你将永远活着--Mhathatma Gandhi
Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi
推荐答案
我想通了,但我有点困惑。
I figured it out, but I am a bit baffled.
"Button_UpdateTimeLog""上面的按钮位于绑定导航器上。我手动将按钮添加到控件集合中,并且它没有"绑定",所以要对任何bindingsource方法(adnew,delete,move ..等)说。将工具栏
中的按钮放到表单上并粘贴上面的更新代码就可以了。绑定源上的按钮会发生什么?
The "Button_UpdateTimeLog" button above is on a binding navigator. I manually added the button to the control collection and it is not 'bound' so to say to any bindingsource methods (adnew,delete,move.., etc). Placing a button from the toolbar onto the form and pasting the above update code works just fine. What could be happening from the button on the bindingsource?
这篇关于DA.update行为不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!