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. C / C++ / MFC
  4. Access Database woes...

Access Database woes...

Scheduled Pinned Locked Moved C / C++ / MFC
databasec++helpquestionannouncement
2 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.
  • T Offline
    T Offline
    Tryhard
    wrote on last edited by
    #1

    Hi all, I am trying to update a record in an Access Database(I am new to DB programming and VC++), from everything I have read the following code should acheive the desired result but it gives a DB exception. Have I missed a readonly flag or got something wrong in my database.open command??? Any pointers greatly appreciated, Thanks in advance, Tryhard Code:- CDatabase database; CString sSql; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "d:\\Docs\\Wayne\\C\\Converse\\CDAT.mdb"; TRY { // Build the creation string for access without DSN sSql.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); // Open the database database.Open(NULL,false,false,sDsn); // Allocate the recordset CRecordset recset( &database ); // Update data sSql = "UPDATE Convhist " "SET GREETINGCOUNT = '1'" "WHERE YOURFIRSTNAME = 'WAYNE'"; // Execute SQL Statement database.ExecuteSQL(sSql); // Close the database database.Close(); } CATCH(CDBException, e) { // If a database exception occured, show error msg AfxMessageBox("Database error: "+e->m_strError); } END_CATCH; }:confused: :confused: Tryhard :-)

    S 1 Reply Last reply
    0
    • T Tryhard

      Hi all, I am trying to update a record in an Access Database(I am new to DB programming and VC++), from everything I have read the following code should acheive the desired result but it gives a DB exception. Have I missed a readonly flag or got something wrong in my database.open command??? Any pointers greatly appreciated, Thanks in advance, Tryhard Code:- CDatabase database; CString sSql; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "d:\\Docs\\Wayne\\C\\Converse\\CDAT.mdb"; TRY { // Build the creation string for access without DSN sSql.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); // Open the database database.Open(NULL,false,false,sDsn); // Allocate the recordset CRecordset recset( &database ); // Update data sSql = "UPDATE Convhist " "SET GREETINGCOUNT = '1'" "WHERE YOURFIRSTNAME = 'WAYNE'"; // Execute SQL Statement database.ExecuteSQL(sSql); // Close the database database.Close(); } CATCH(CDBException, e) { // If a database exception occured, show error msg AfxMessageBox("Database error: "+e->m_strError); } END_CATCH; }:confused: :confused: Tryhard :-)

      S Offline
      S Offline
      solex
      wrote on last edited by
      #2

      Are you sure that your database could be opened? You are not checking the return value. The rest of the code is fine, but there is no need for a CRecordset. What does the error string say? A vast majority of our imports comes from outside the country. George W. Bush

      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