Таблица создана для каждого предмета (например, английский язык, математика), а таблица студентов связана с каждой из тематических таблиц, я был бы благодарен, если бы кто-то мог любезно изменить код ниже разрешите мне выполнить команду delete, чтобы удалить запись из этих нескольких таблиц.Удаление записи из нескольких таблиц
Одна из важных проблем заключается в том, что должен быть способ выполнить команду delete так, чтобы связанная запись также могла быть удалена из любой дополнительной тематической таблицы, которая впоследствии будет создана в будущем при введении нового объекта.
Dim cd As String
If txtName.Text = "" And cboDay.Text = "" And cboMonth.Text = "" And txtYear.Text = "" And lblAge.Text = "" And radioMale.Checked = False Or RadioFemale.Checked = False And txtGName.Text = "" And txtMPhone.Text = "" And txtEmail.Text = "" And txtAddress.Text = "" And txtCity.Text = "" And cboRegion.Text = "" And PictureBox1.ImageLocation = "" Then
MessageBox.Show("There is no record selected to delete. Search for the record to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
cd = MessageBox.Show("You are about to delete this record. Are you sure you want to delete?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If cd = vbYes Then
cmd = New SqlCommand("Delete from StudentDetails.Registration where StudentId='" & txtStudentId.Text & "'", cn)
cmd.ExecuteNonQuery()
cmd = New SqlCommand("Delete from StudentDetails.Students where StudentId='" & txtStudentId.Text & "'", cn)
cmd.ExecuteNonQuery()
cmd = New SqlCommand("Delete from ProgramDetails.EnglishLanguage where StudentId='" & txtStudentId.Text & "'", cn)
cmd.ExecuteNonQuery()
MessageBox.Show("Record deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information)
Showgrid()
txtStudentId.Clear()
txtName.Clear()
cboDay.Text = ""
cboMonth.Text = ""
lblAge.Text = ""
txtNationality.Clear()
If radioMale.Checked = True Then
Sex = ""
End If
cboStudentType.Text = ""
cboHouse.Text = ""
cboRoom.Text = ""
txtGName.Clear()
txtMPhone.Clear()
txtHPhone.Clear()
txtEmail.Clear()
txtAddress.Clear()
txtCity.Clear()
cboRegion.Text = ""
PictureBox1.Image = PictureBox1.ErrorImage
txtStudentId.Focus()
End If
End If
Не могли бы вы изменить мой кода в отношении вашего предложения. – Akaglo
@Akaglo метод каскада выполняется через сервер sql. – AbZy
@Akaglo Обновлен мой ответ. – AbZy