당신은 내가 그 답을 모른다는 흥미로운 질문을했습니다. 약간의 연구 후에 나는 이것을 발견했고 그것은 유망 해 보인다. 그러나 나는 그것을 사용한 적이 없으며 그것이 잘 작동하는지 그리고 얼마나 잘 작동하는지 입증 할 수 없다.
도 잘 모르겠지만 OleDbAdapter
개체를 생성했다는 것을 막연하게 회상합니다.이 코드를 연결할 수있는 RowUpdated
이벤트가 표시됩니다.
여기 흥미로운 MSDN 코드 부분을 붙여 넣은 : (Link to full documentation)
' Create the INSERT command for the new category.
adapter.InsertCommand = New OleDbCommand(_
"INSERT INTO Categories (CategoryName) Values(?)", connection)
adapter.InsertCommand.CommandType = CommandType.Text
그리고 후크 업 및 이벤트 리스너
' Include an event to fill in the Autonumber value.
AddHandler adapter.RowUpdated, _
New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
RowUpdated
에 동일한 연결로 @@Identity
를 얻습니다.
Private Shared Sub OnRowUpdated(_
ByVal sender As Object, ByVal e As OleDbRowUpdatedEventArgs)
' Conditionally execute this code block on inserts only.
If e.StatementType = StatementType.Insert Then
' Retrieve the Autonumber and store it in the CategoryID column.
Dim cmdNewID As New OleDbCommand("SELECT @@IDENTITY", _
connection)
e.Row("CategoryID") = CInt(cmdNewID.ExecuteScalar)
e.Status = UpdateStatus.SkipCurrentRow
End If
End Sub
는 희망이 당신을 도와 주거나 적어도 사람이 바로 저를 설정합니다 :
http://support.microsoft.com/kb/815629을 – JeffO
즉, 모든 코드 제프와 함께입니다. 내가 만든 테이블 연결은 내가 TableAdapter Wizards에서 만든 어댑터 (내가 생각한)입니다. –