Ho un semplice gestioanle con due tabelle, una con le aziende ed una con i contratti delle rispettive aziende, relazione 1 a molti. Il database è access e gli ho detto di applicare l'integrità referenziale, di aggiornare ed eliminare i campi correlati a catena.
Per l'inserimento dei dati ho due datagridview ed un pulsantino che dopo aver aggironato i data grid effettua due update sui TableAdapter delle rispettive tabelle per aggiornare i loro contenuti, il codice è il seguente:
codice:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Tasto di update datagrid: Eseguo prima il controllo delle tabelle, per controllare che non siano vuote.
If (Me.AziendaTableAdapter.Update(Me.Db1DataSet.Azienda) <> 0) Then
Me.AziendaTableAdapter.Update(Me.Db1DataSet.Azienda)
End If
If (Me.ContrattoTableAdapter.Update(Me.Db1DataSet.Contratto) <> 0) Then
Me.ContrattoTableAdapter.Update(Me.Db1DataSet.Contratto)
End If
End Sub
Ora, con il database immacolato, alla prima apertura del programma, quando faccio il primo inserimento e clicco il tasto per effettuare il tableadapter.update mi da il seguente errore:
(l'errore me lo da solo al primo salvataggio con il database senza contenuti, a tutte le volte successive va liscio come l'olio)
codice:
Le informazioni su come richiamare il debug JIT (Just-In-Time) anziché questa finestra
sono riportate in fondo al messaggio.
************** Testo dell'eccezione **************
System.Data.OleDb.OleDbException: Impossibile aggiungere o modificare il record. Nella tabella "Azienda" è necessario un record correlato.
in System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
in System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
in System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
in System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
in System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
in Gestionale.db1DataSetTableAdapters.ContrattoTableAdapter.Update(ContrattoDataTable dataTable) in C:\Documents and Settings\Guido\Documenti\Visual Studio 2005\Projects\Gestionale\Gestionale\db1DataSet.Designer.vb:riga 2228
in Gestionale.Form1.Button1_Click_1(Object sender, EventArgs e) in C:\Documents and Settings\Guido\Documenti\Visual Studio 2005\Projects\Gestionale\Gestionale\Form1.vb:riga 93
in System.Windows.Forms.Control.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ButtonBase.WndProc(Message& m)
in System.Windows.Forms.Button.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Assembly caricati **************
mscorlib
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Gestionale
Versione assembly: 1.0.0.0
Versione Win32: 1.0.0.0
Base di codice: file:///C:/Documents%20and%20Settings/Guido/Documenti/Visual%20Studio%202005/Projects/Gestionale/Gestionale/obj/Debug/Gestionale.exe
----------------------------------------
Microsoft.VisualBasic
Versione assembly: 8.0.0.0
Versione Win32: 8.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Xml
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Windows.Forms.resources
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_it_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Configuration
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Transactions
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Versione assembly: 2.0.0.0
Versione Win32: 2.0.50727.42 (RTM.050727-4200)
Base di codice: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
************** Debug JIT **************
Per attivare il debug JIT, è necessario impostare il valore
jitDebugging nella sezione system.windows.forms del file di configurazione
dell'applicazione o del computer (machine.config).
L'applicazione inoltre deve essere compilata con il debug
attivato.
Ad esempio:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
Quando il debug JIT è attivato, tutte le eccezioni non gestite
vengono inviate al debugger JIT registrato nel computer,
anziché essere gestite da questa finestra di dialogo.
Saopete dirmi da cosa dipende e come eliminare tale errore?