syntax error in INSERT INTO statement

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi all,

I am trying to create, and write data into microsoft access file using
CDaoDatabase and CDaoRecordset in Microsoft visual studio 8.0. I am new
to working with databases.

It is actually a example code from a website. The code is,

CDaoDatabase database;

CDaoRecordset recordset(&database);
CString lpszFile = "C:\\Database.mdb";
database.Create(lpszFile);
//database.Open(lpszFile);
_ASSERTE( _CrtCheckMemory( ) );
CString SqlCmd ="CREATE TABLE MINECOORDINATES (X VARCHAR(10)"
", Y VARCHAR(10)"
", Z VARCHAR(10))" ;
database.Execute(SqlCmd);
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM MineCoordinates", 0);
database.Execute("INSERT INTO MineCoordinates(X);");
database.Execute("INSERT INTO MineCoordinates(Y);");
database.Execute("INSERT INTO MineCoordinates(Z);");

recordset.AddNew();
recordset.SetFieldValue("X","10");
recordset.SetFieldValue("Y","13");
recordset.SetFieldValue("Z","13");
recordset.Update();
recordset.MoveNext();
recordset.AddNew();
recordset.SetFieldValue("X","11");
recordset.SetFieldValue("Y","1");
recordset.SetFieldValue("Z","3");
recordset.Update(); */
COleVariant olevar;
while(!recordset.IsEOF());
{
olevar.ChangeType(VT_BSTR, NULL);
recordset.GetFieldValue("X",olevar);
CString strData = (LPCSTR)olevar.pbstrVal;
// Code for inserting data into a listbox, for example
recordset.MoveNext();
}

At the run time i get an error stating, syntax error in INSERT INTO
statement. Could anyone please let me know, what is the error here?

Thank you,

Priya

.



Relevant Pages

  • Re: syntax error in INSERT INTO statement
    ... and write data into microsoft access file using ... CDaoDatabase and CDaoRecordset in Microsoft visual studio 8.0. ...
    (microsoft.public.vc.language)
  • Re: Problem linking DAO with MFC and Unicode
    ... CDaoRecordset using Visual C++ 6.0. ... the CDaoDatabase and CDaoRecordset). ... This works ok when I compile and link without the _UNICODE ... when I build the project with Unicode I get the link error ...
    (microsoft.public.vc.database)
  • Database problem
    ... I am implementing a database using MS ACESS.I am using CDaoDatabase and ... CDaoRecordset to acess data.I am able to get string and integer values.Can ...
    (microsoft.public.vc.database)
  • CDaodatabase CDaorecorset mfc Latest version
    ... I use the mfc and "afxdao.h" with CDaoDatabase and CDaoRecordset. ... David BIGNON ...
    (microsoft.public.vc.mfc)