GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jul-2006, 05:15
rajamca rajamca is offline
New Member
 
Join Date: Jun 2006
Posts: 5
rajamca is on a distinguished road

how to insert a record in Access database using sql statements


hi,


I did a program for inserting a record in Access database using sql statements using CDatabase class. the code is as follows. it doesn't work properly.

CPP / C++ / C Code:
CString sDriver;
CString sDsn;
CString sFile;
CDatabase db;
CString SqlString;


sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
sFile = "E:\\raja\\Temp\\simpleDoc\\addressbook.mdb";

sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
db.Open(NULL,false,false,sDsn);

	
try
{
       CRecordset rs(&db);


       SqlString="INSERT INTO addbook VALUES('Xanxa','Industrial    Estate','Guindy','Chennai','TN',346564,56454,45666,'contact@xanxa.com','www.xanxa.com','welcome')";
		
       AfxMessageBox(SqlString);

       rs.Open(CRecordset::snapshot,SqlString,CRecordset::appendOnly);		
		
       rs.Close();

}
catch(CDBException *p)
{
      AfxMessageBox(p->m_strError);
}

if any body know, plz send me details.

Regards,

Raja.P
Chennai.
Last edited by LuciWiz : 22-Jul-2006 at 05:30. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 22-Jul-2006, 12:12
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 958
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: how to insert a record in Access database using sql statements


The problem is that you are trying to use a recordset for a SQL statement that does not return records, as you are performing an INSERT (not a SELECT).

This is all you need in the try block for that SQL:
CPP / C++ / C Code:
     SqlString="INSERT INTO addbook VALUES('Xanxa','Industrial    Estate','Guindy','Chennai','TN',346564,56454,45666,'contact@xanxa.com','www.xanxa.com','welcome')";
     db.ExecuteSQL( SqlString );
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusing Assignment/Three tier database access with c++ and oracle Dyshein C++ Forum 0 01-May-2006 20:45
Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 lyuboe MySQL / PHP Forum 0 11-May-2005 04:31
retrieve record from access database in MFC jinshi MS Visual C++ / MFC Forum 0 02-Feb-2005 09:29
Access database and Visual basic programming confused_pig C++ Forum 0 11-Jan-2005 18:59
insert data into database jilshi Web Design Forum 0 29-Apr-2004 22:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:51.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.