我已经更新了TableAdapter的高级选项,因此它会刷新数据表。
我正在寻找在使用TableAdapter.Update后立即检索新添加的行的SCOPE_IDENTITY。
如何实现这一目标?
谢谢!
答案 0 :(得分:1)
TableAdapter
会自动在插入语句的末尾插入SCOPE_IDENTITY
。 DataRow
包含插入后新创建的标识值。在将行添加到表中并通过TableAdapter
更新之前,不要设置PK列。
Dim daLocation As New LocationTableAdapter() ' the TableAdapter
Dim newLocation = Location.NewLocationRow() ' the new DataRow
newLocation.Name = "Berlin"
Location.AddLocationRow(newLocation)
' now update the DataTable or the DataRow with the TableAdapter
Dim numRowsUpdated As Int32 = daLocation.Update(newLocation)
Dim id As Int32 = newLocation.idLocation ' now the new ID is available