【问题标题】:TableAdapter.Update Does Not Save Imported RowTableAdapter.Update 不保存导入的行
【发布时间】:2014-04-22 01:38:20
【问题描述】:

我的数据库出现问题。我的应用程序部分的目的很简单;当用户标记工作分配完成时,它将使用“table.ImportRow”方法将一个DataRow 从“activeUnits”传输到另一个名为“completedUnits”的表,然后使用表适配器将此更改更新到核心数据库。但是,在测试此函数时,Dataset 已在内部成功完成行的移动,但在使用 TableAdapter.Update 方法时,数据库的数据更新仅返回为“0”,没有进行任何更改或导致错误。

                Try
                        Dim activeRowMove As DataRow = Me.AssignmentDataSet.activeUnits.Rows(currentIndex)
                        Dim newMove As DataTable = Me.AssignmentDataSet.completedUnits



                        newMove.ImportRow(activeRowMove)


                        'UPDATE CHANGES
                        Me.Validate()
                        CompletedUnitsBindingSource.EndEdit()
                        Console.WriteLine(Me.CompletedUnitsTableAdapter.Update(Me.AssignmentDataSet.completedUnits))

                        activeUnitsTitle.Text = ("Assignment Completed!")

                    Catch ex As Exception
                        Console.WriteLine("Failed to update new table: " & ex.ToString)
                        activeUnitsTitle.Text = ("Failed to save!")

                    End Try

我的代码中是否存在我做错了的地方,或者任何更好或更有效的移动数据行的方法都值得赞赏!

我的数据库未复制在我项目的 bin 文件夹中,每次更新都转到一个中心位置。

如果需要,以下链接是我当前布局和数据的两个屏幕截图 - here

【问题讨论】:

    标签: database vb.net dataset datarow


    【解决方案1】:

    来自 MSDN:

    Calling ImportRow preserves the existing DataRowState along with other values in the row
    

    因此,如果“from”表中的 DataRowState 是 Unchanged,那么它的状态将在“to”表中保持为 Unchanged,并且不会被保存。

    确保将新导入行的DataRowState改为Added

    干杯

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多