Access Database woes...
-
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 :-)
-
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 :-)
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