일부 프로젝트 (VB.Net & SQL Server)에서 작업하고 있습니다 환자 & 예약 시나리오. ,2 SqlDataAdapters의 데이터 저장 순차적으로
SqlAdap = New SqlDataAdapter(String.Format("select * from {0}",Patient),SqlConMain)
SqlAdap.Fill(DS,"Patient")
Dim SqlCmd As New SqlCommandBuilder(SqlAdap)
SqlAdap.InsertCommand = SqlCmd.GetInsertCommand
SqlAdap.DeleteCommand = SqlCmd.GetDeleteCommand
SqlAdap.UpdateCommand = SqlCmd.GetUpdateCommand
BindSrc.DataSource = DS
BindSrc.DataMember = "Patient"
BindNavMain.BindingSource = BindSrc
SqlAdapAppointment = New SqlDataAdapter("select * from Appointment", SqlConMain)
SqlAdapAppointment.Fill(DS, "Appointment")
Dim SqlCmdAppointment As New SqlCommandBuilder(SqlAdapAppointment)
SqlAdapAppointment.InsertCommand = SqlCmdAppointment.GetInsertCommand
SqlAdapAppointment.DeleteCommand = SqlCmdAppointment.GetDeleteCommand
SqlAdapAppointment.UpdateCommand = SqlCmdAppointment.GetUpdateCommand
Dim Rel As New DataRelation("FK_Patient_Appointment",
DS.Tables("Patient").Columns("PatientId"),
DS.Tables("Appointment").Columns("PatientId"), False)
Rel.Nested = False
DS.Relations.Add(Rel)
BindSrcAppointment.DataSource = BindSrc
BindSrcAppointment.DataMember = "FK_Patient_Appointment"
BindNavAppointment.BindingSource = BindSrcAppointment
모든 것이 .. 잘 을 작동하지만 나는 그것의 BindingNavigator을 사용하여 새 환자를 추가 한 경우 :
이 대중 선언은 다음과 같습니다
Dim DS As New DataSet
Dim SqlAdap, SqlAdapAppointment As SqlDataAdapter
Dim BindSrc, BindSrcAppointment As New BindingSource
와 나는 Load 이벤트에 바인딩 설정 그런 다음 약속의 BindingNavigator를 사용하여 약속을 추가했습니다.
그런 다음 모두 저장하려고 시도하면 환자 데이터가 저장됩니다. 이 약속 데이터를 저장 할 수 없기 때문에 uccessfully하지만, 후에 오류가 발생합니다 그 새로운 환자 ID
에 관련이 내 저장 코드는 : 나는 시도하는 경우
BindSrcAppointment.EndEdit()
BindSrc.EndEdit()
Dim TblPatient As DataTable = DS.Tables("Patient").GetChanges()
If TblPatient IsNot Nothing Then
SqlAdap.Update(TblPatient)
DS.Tables("Patient").AcceptChanges()
End If
Dim TblAppointment As DataTable = DS.Tables("Appointment").GetChanges()
If TblAppointment IsNot Nothing Then
SqlAdapAppointment.Update(TblAppointment)
DS.Tables("Appointment").AcceptChanges()
End If
성공적 물론 저장 데이터베이스에 이미 저장된 데이터가있는 환자에게 약속을 추가하려면
2 어댑터의 데이터를 한 번에 순차적으로 저장하는 방법이 있는지 알고 싶습니다.