我有这段代码应该更新我的访问数据库,但我一直收到一条错误消息:
由于表“MembrosCompasso”具有相关记录,因此无法更改或删除注册表。
这是我的代码:
Dim query1 As String = "UPDATE MembrosCompasso SET MembrosCompasso.BI=@compass_bi WHERE MembrosCompasso.BI=Membros.BI" ' Membros.Pai=@pai, Membros.Mae=mae WHERE BI=@BI"
Dim query As String = "UPDATE Membros SET Membros.BI=@num_bi, Membros.Nome=@nome, Membros.Hablitacoes=@hablitacoes, Membros.Contribuinte=@contribuinte, Membros.Telemov=@telemov, Membros.DataNasc=@natnasc, Membros.LocalNasc=@localnasc, Membros.DataBaptismo=@databapt, Membros.LocalBapt=@localbapt, Membros.Sexo=@sexo, Membros.Naturalidade=@natu, Membros.Profissao=@prof, Membros.Estadocivil=@estadciv, Membros.DataCasamento=@datacas, Membros.LocalCasamento=@localcas, Membros.Notas=@notas, Membros.Email=@email WHERE Membros.BI=@BI"
con.Close()
con.Open()
Dim command As New OleDbCommand(query, con)
Dim command1 As New OleDbCommand(query1, con)
' Indicação dos parâmetros que serão actualizados
command1.Parameters.Add("@compass_bi", OleDbType.VarChar).Value = BI.Text
command.Parameters.Add("@num_bi", OleDbType.VarChar).Value = BI.Text
command.Parameters.Add("@nome", OleDbType.VarChar).Value = Nome.Text
command.Parameters.Add("@hablitacoes", OleDbType.VarChar).Value = hablitacoes.Text
command.Parameters.Add("@contribuinte", OleDbType.VarChar).Value = ncront.Text
command.Parameters.Add("@telemov", OleDbType.VarChar).Value = telmov.Text
command.Parameters.Add("@natnasc", OleDbType.VarChar).Value = datnasc.Text
command.Parameters.Add("@localnasc", OleDbType.VarChar).Value = NascLocal.Text
command.Parameters.Add("@databapt", OleDbType.VarChar).Value = DataBapt.Text
command.Parameters.Add("@localbapt", OleDbType.VarChar).Value = LocalBapt.Text
command.Parameters.Add("@sexo", OleDbType.VarChar).Value = sexo.Text
command.Parameters.Add("@natu", OleDbType.VarChar).Value = natu.Text
command.Parameters.Add("@prof", OleDbType.VarChar).Value = profi.Text
command.Parameters.Add("@estadciv", OleDbType.VarChar).Value = estciv.Text
command.Parameters.Add("@datacas", OleDbType.VarChar).Value = datcas.Text
command.Parameters.Add("@localcas", OleDbType.VarChar).Value = localcas.Text
command.Parameters.Add("@notas", OleDbType.VarChar).Value = notas.Text
command.Parameters.Add("@email", OleDbType.VarChar).Value = email.Text
command.Parameters.Add("@BI", OleDbType.VarChar).Value = numero_BI
这里有我的访问数据库架构的屏幕截图。