Problem with Access
-
Hi, I'm stuck with an Access (XP) DB. In the .mdb I have two tables, I load them in a dataset (with the same tables) and I work with the data. Up to here, everything is fine. To save back data in the DB I use a code I got from MSDN. Two different, but very similar, codes for each table. With one it works, not with the other! Here's the code: Dim conn As New OleDb.OleDbConnection Dim SelectCMD As OleDb.OleDbCommand Dim CustomCB As OleDb.OleDbCommandBuilder Dim DBAdapter As New OleDb.OleDbDataAdapter DB.AcceptChanges() conn.ConnectionString = String.Concat("Provider=Microsoft.Jet.OLEDB.4.0;Data source=", cfgDBDirectory, "\x.mdb") Try conn.Open() SelectCMD = New OleDb.OleDbCommand("SELECT * FROM Coordinate", conn) SelectCMD.CommandTimeout = 30 DBAdapter.SelectCommand = SelectCMD CustomCB = New OleDb.OleDbCommandBuilder(DBAdapter) DBAdapter.Update(DB.Coordinate) Catch ex As Exception MessageBox.Show(String.Concat("Errore nell'accesso alla base dati archivio:", ex.ToString), "RFGPRII", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub The exception I got report a problem with the INSERT function. With the other table, code equal but table names, everything works! Thanks for the help Briga
-
Hi, I'm stuck with an Access (XP) DB. In the .mdb I have two tables, I load them in a dataset (with the same tables) and I work with the data. Up to here, everything is fine. To save back data in the DB I use a code I got from MSDN. Two different, but very similar, codes for each table. With one it works, not with the other! Here's the code: Dim conn As New OleDb.OleDbConnection Dim SelectCMD As OleDb.OleDbCommand Dim CustomCB As OleDb.OleDbCommandBuilder Dim DBAdapter As New OleDb.OleDbDataAdapter DB.AcceptChanges() conn.ConnectionString = String.Concat("Provider=Microsoft.Jet.OLEDB.4.0;Data source=", cfgDBDirectory, "\x.mdb") Try conn.Open() SelectCMD = New OleDb.OleDbCommand("SELECT * FROM Coordinate", conn) SelectCMD.CommandTimeout = 30 DBAdapter.SelectCommand = SelectCMD CustomCB = New OleDb.OleDbCommandBuilder(DBAdapter) DBAdapter.Update(DB.Coordinate) Catch ex As Exception MessageBox.Show(String.Concat("Errore nell'accesso alla base dati archivio:", ex.ToString), "RFGPRII", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub The exception I got report a problem with the INSERT function. With the other table, code equal but table names, everything works! Thanks for the help Briga
What is the EXACT exception message? Without it, there's nothing we can do to help you. My first GUESS would be that there was a problem with a duplicate primary key, but of course, I'm only guessing... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
What is the EXACT exception message? Without it, there's nothing we can do to help you. My first GUESS would be that there was a problem with a duplicate primary key, but of course, I'm only guessing... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Well things are weird. I also added an XML just for text. So I load the DB with .readxml and before using the Update methos I also save it to an XML file with WriteXML. In the beginning I got problem with XML in reading (not in saving) due to invalid values. I changed every field as nillable and now it works (XML). The Update method doesn't generate any exception anymore but the .mdb is empty. The new code is: DB.AcceptChanges() DB.WriteXml("c:\RF.XML") ' *** salvataggio XML conn.ConnectionString = String.Concat("Provider=Microsoft.Jet.OLEDB.4.0;Data source=", cfgDBDirectory, "\rfgprii.mdb") Try conn.Open() SelectCMD = New OleDb.OleDbCommand("SELECT * FROM Coordinate", conn) SelectCMD.CommandTimeout = 30 DBAdapter.SelectCommand = SelectCMD CustomCB = New OleDb.OleDbCommandBuilder(DBAdapter) DBAdapter.Update(DB.Coordinate) Catch ex As Exception MessageBox.Show(String.Concat("Errore nell'accesso alla base dati archivio:", ex.ToString), "RFGPRII", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Now I also put a rem in front of the .writexml just to see if that instruction was affecting the Update. Still it generates no exception but the .mdb is empty. So to recap the exception was due to the nillable parameter (although there were no null values) and it's gone. The problem now is that the Update method does not work. The DB is empty. Any clues? Thanks for the reply Briga