VB.Net SQL DataAdapter首次运行时不更新

时间:2017-07-07 10:37:07

标签: vb.net sqldataadapter

我正在使用SQL DataAdapter(sqlDa),并且在单击复选框事件时,sqlDa应该运行更新命令。

调用代码,但更新事件实际上并没有触发,我不确定为什么。

我已经介入并且没有错误, 我运行了SQL Profiler,它显示没有触发SQL事件 最初没有创建一个初始化程序,并且绑定事件在我正在使用的复选框上

所以,我有点难过,需要一些帮助。

我正在使用的代码是

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
    '

任何和所有帮助非常感谢

西蒙

1 个答案:

答案 0 :(得分:0)

发现问题

需要添加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