Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with Access

Problem with Access

Scheduled Pinned Locked Moved Visual Basic
helpdatabaseannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Briga
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • B 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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        B Offline
        B Offline
        Briga
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups