2012-12-05 4 views
0

TableAdapter의 고급 옵션을 업데이트하여 데이터 테이블을 새로 고칩니다.TableAdapter 업데이트 후 SCOPE_IDENTITY()

TableAdapter.Update를 사용하면 새로 추가 된 행의 SCOPE_IDENTITY를 검색하려고합니다.

어떻게 달성 할 수 있습니까?

감사합니다.

답변

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 
+0

완벽하게 작동합니다. 고마워요! – Gil