Click here to Skip to main content
15,908,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: access violation in release mode Pin
Nynaeve3-Oct-05 6:49
Nynaeve3-Oct-05 6:49 
QuestionShared Memory - Old References Pin
sweep1233-Oct-05 5:53
sweep1233-Oct-05 5:53 
Questiontrigger events Pin
Anonymous3-Oct-05 5:46
Anonymous3-Oct-05 5:46 
QuestionThe amazing vanishing keypress Pin
hairy_hats3-Oct-05 5:29
hairy_hats3-Oct-05 5:29 
AnswerRe: The amazing vanishing keypress Pin
icabod3-Oct-05 5:55
icabod3-Oct-05 5:55 
GeneralRe: The amazing vanishing keypress Pin
icabod3-Oct-05 6:06
icabod3-Oct-05 6:06 
GeneralRe: The amazing vanishing keypress Pin
hairy_hats3-Oct-05 23:11
hairy_hats3-Oct-05 23:11 
QuestionCRecordSet ? - adding new records Pin
ddmcr3-Oct-05 3:22
ddmcr3-Oct-05 3:22 
Hello everybody,
I have next problem :

I have a MFC Dialog based application and i am retrieving some info from a *.mdb database using CDatabase and CRecordSet classes. I am doing this without any problems.
But my question is how to add a new record in this database ?
My code looks like this :

CDatabase database;
CString   sSQL;
CString   sName,sSurname,sID;
CString   sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString   sFile = "c:\\db1.mdb";
CString   sDsn;
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);

TRY
	{
		database.Open(NULL,false,false,sDsn);
		CRecordset recset( &database );
                // Here i want to add for example new record
                // "ID=5" , "Name=Jon" , "Surname =Doe ".
		database.Close();
	}
CATCH(CDBException, e)
	{
		// If a database exception occured, show error msg
		AfxMessageBox("Database error: "+e->m_strError);
	}
END_CATCH;


I guess i'm supposed to use AddNew() ,Requiry(),Update() functions.

MSDN says : "AddNew prepares a new, empty record using the recordset's field data members. After you call AddNew, set the values you want in the recordset's field data members. " - how can i set the values ???



"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill



-- modified at 9:22 Monday 3rd October, 2005
AnswerRe: CRecordSet ? - adding new records Pin
vikas amin3-Oct-05 3:54
vikas amin3-Oct-05 3:54 
QuestionRe: CRecordSet ? - adding new records Pin
ddmcr3-Oct-05 4:06
ddmcr3-Oct-05 4:06 
AnswerRe: CRecordSet ? - adding new records Pin
vikas amin3-Oct-05 4:36
vikas amin3-Oct-05 4:36 
QuestionRe: CRecordSet ? - adding new records [modified] Pin
ddmcr3-Oct-05 5:33
ddmcr3-Oct-05 5:33 
AnswerRe: CRecordSet ? - adding new records Pin
hairy_hats3-Oct-05 5:24
hairy_hats3-Oct-05 5:24 
GeneralRe: CRecordSet ? - adding new records Pin
ddmcr3-Oct-05 5:54
ddmcr3-Oct-05 5:54 
AnswerRe: CRecordSet ? - adding new records Pin
Ghasrfakhri3-Oct-05 5:41
Ghasrfakhri3-Oct-05 5:41 
GeneralRe: CRecordSet ? - adding new records Pin
ddmcr3-Oct-05 5:51
ddmcr3-Oct-05 5:51 
AnswerRe: CRecordSet ? - adding new records Pin
Ghasrfakhri3-Oct-05 5:57
Ghasrfakhri3-Oct-05 5:57 
QuestionTransparent drawing Pin
Jagadeesh VN3-Oct-05 2:55
Jagadeesh VN3-Oct-05 2:55 
AnswerRe: Transparent drawing Pin
vikas amin3-Oct-05 3:24
vikas amin3-Oct-05 3:24 
AnswerRe: Transparent drawing Pin
Chris Losinger3-Oct-05 6:28
professionalChris Losinger3-Oct-05 6:28 
AnswerRe: Transparent drawing Pin
Lane Yu3-Oct-05 19:22
Lane Yu3-Oct-05 19:22 
Questionword addin Pin
a0kboy3-Oct-05 2:12
a0kboy3-Oct-05 2:12 
QuestionBitmap dialog Pin
rajeev823-Oct-05 2:04
rajeev823-Oct-05 2:04 
AnswerRe: Bitmap dialog Pin
Mircea Puiu3-Oct-05 2:28
Mircea Puiu3-Oct-05 2:28 
AnswerRe: Bitmap dialog Pin
vikas amin3-Oct-05 2:51
vikas amin3-Oct-05 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.