2012-04-27 98 views
1

我有這樣的代碼應該更新我的訪問數據庫,但我不斷收到一個錯誤說:的Visual Basic 2010錯誤訪問數據庫更新查詢

這是不可能如此更改或刪除,因爲該表的regists 'MembrosCompasso'有相關記錄。

這是我的代碼:

Dim query1 As String = "UPDATE MembrosCompasso SET [email protected]_bi WHERE MembrosCompasso.BI=Membros.BI" ' [email protected], Membros.Mae=mae WHERE [email protected]" 
Dim query As String = "UPDATE Membros SET [email protected]_bi, [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] WHERE [email protected]" 

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 

還有就是我的Access數據庫模式here的屏幕截圖。

回答

1

看起來您正在嘗試更新表MembrosCompasso,然後再在表Membros中進行更改。
由於您將MembrosCompasso.BI設置爲與Membros.BI相關,因此它必須首先存在於該表中。

如果您將Access中的關係設置爲自動更新,則不必執行任何手動更新至MembrosCompasso,它們將在您更新源字段時自動更新。

例如,說我有一個PO表,有很多POItem
我可以將它們設置爲以下之間的一個一對多的關係:

enter image description here

在這種情況下,如果我更新PO.ID,所有POItem.POID字段將被更新。
同樣,如果我刪除給定的PO記錄,則所有相關的POItem記錄也將被刪除。

看看MS Access documentation about table relationships

+0

thanx那是問題 – user1341926 2012-05-01 20:02:30