VB.Net SQL DataAdapter 未首先更新 运行
VB.Net SQL DataAdapter Not updating on first run
我正在使用 SQL DataAdapter (sqlDa),在单击复选框事件时,sqlDa 应该 运行 更新命令。
调用了代码,但实际上并没有触发更新事件,我不确定为什么。
我已经一步步完成了,没有错误,
我有 运行 SQL Profiler,它显示没有 SQL 事件被触发
最初没有 Initializer 所以创建了一个,绑定事件在我正在使用的复选框上
所以,我有点难过,需要一些帮助。
我正在使用的代码是
Public Sub New()
InitializeComponent()
End Sub
Private Sub boundCheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles boundCheckBox.CheckedChanged
ControlSettingsBindingSource.EndEdit()
Me.ControlSettingsTableAdapter.Update(Me.BoundTestDataSet.controlSettings)
Call diagnosticCheck(boundCheckBox.Checked) ' this is for diagnostic purposes only
End Sub
Public Overloads Overridable Function Update(ByVal dataTable As boundTestDataSet.controlSettingsDataTable) As Integer
Return Me.Adapter.Update(dataTable)
End Function
在初始化程序中,这是我正在使用的控件
'boundCheckBox
'
Me.boundCheckBox.AutoSize = True
Me.boundCheckBox.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Me.ControlSettingsBindingSource, "checkBoxSetting", True))
Me.boundCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.boundCheckBox.Location = New System.Drawing.Point(10, 62)
Me.boundCheckBox.Margin = New System.Windows.Forms.Padding(4, 3, 4, 3)
Me.boundCheckBox.Name = "boundCheckBox"
Me.boundCheckBox.Size = New System.Drawing.Size(590, 40)
Me.boundCheckBox.TabIndex = 0
Me.boundCheckBox.Text = "CheckBox Bound To 'checkBoxSetting'"
Me.boundCheckBox.UseVisualStyleBackColor = True
'
非常感谢任何帮助
西蒙
找到问题
需要添加ControlSettingsBindingSource.ResetBindings(False)
Private Sub boundCheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles boundCheckBox.CheckedChanged
ControlSettingsBindingSource.EndEdit()
ControlSettingsBindingSource.ResetBindings(False)
Me.ControlSettingsTableAdapter.Update(Me.BoundTestDataSet.controlSettings)
Call diagnosticCheck(boundCheckBox.Checked) ' this is for diagnostic purposes only
End Sub
我正在使用 SQL DataAdapter (sqlDa),在单击复选框事件时,sqlDa 应该 运行 更新命令。
调用了代码,但实际上并没有触发更新事件,我不确定为什么。
我已经一步步完成了,没有错误, 我有 运行 SQL Profiler,它显示没有 SQL 事件被触发 最初没有 Initializer 所以创建了一个,绑定事件在我正在使用的复选框上
所以,我有点难过,需要一些帮助。
我正在使用的代码是
Public Sub New()
InitializeComponent()
End Sub
Private Sub boundCheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles boundCheckBox.CheckedChanged
ControlSettingsBindingSource.EndEdit()
Me.ControlSettingsTableAdapter.Update(Me.BoundTestDataSet.controlSettings)
Call diagnosticCheck(boundCheckBox.Checked) ' this is for diagnostic purposes only
End Sub
Public Overloads Overridable Function Update(ByVal dataTable As boundTestDataSet.controlSettingsDataTable) As Integer
Return Me.Adapter.Update(dataTable)
End Function
在初始化程序中,这是我正在使用的控件
'boundCheckBox
'
Me.boundCheckBox.AutoSize = True
Me.boundCheckBox.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Me.ControlSettingsBindingSource, "checkBoxSetting", True))
Me.boundCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.boundCheckBox.Location = New System.Drawing.Point(10, 62)
Me.boundCheckBox.Margin = New System.Windows.Forms.Padding(4, 3, 4, 3)
Me.boundCheckBox.Name = "boundCheckBox"
Me.boundCheckBox.Size = New System.Drawing.Size(590, 40)
Me.boundCheckBox.TabIndex = 0
Me.boundCheckBox.Text = "CheckBox Bound To 'checkBoxSetting'"
Me.boundCheckBox.UseVisualStyleBackColor = True
'
非常感谢任何帮助
西蒙
找到问题
需要添加ControlSettingsBindingSource.ResetBindings(False)
Private Sub boundCheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles boundCheckBox.CheckedChanged
ControlSettingsBindingSource.EndEdit()
ControlSettingsBindingSource.ResetBindings(False)
Me.ControlSettingsTableAdapter.Update(Me.BoundTestDataSet.controlSettings)
Call diagnosticCheck(boundCheckBox.Checked) ' this is for diagnostic purposes only
End Sub