Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting to an Access database
Message
 
To
13/11/2001 15:34:31
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00581101
Message ID:
00581141
Views:
20
>I need some help on the following :
>
>I have been trying to insert a record to an Access database. I get an error when I try to insert it to a date field in the Access database.
>Here is the code :
>
>******************************************************************
>lcCourse = CourseList.Name && Get the name from CourseList cursor
>lcEmployeeName = EmployeeList.Name && get the employee form EmployeeList cursor
>
>ldDate = DTOC(Thisform.txtTrainingDate.Value)
>
>lcMDBStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=l:\ehs\data\eh&s.mdb;"
>oCn = Create("adodb.Connection")
>oCn.Open(lcMDBStr)
>oCn.Execute("INSERT INTO Training ( course , name , date );
> Values ( " + "'" + lcCourse + "' , ;
> " + "'" + lcEmployeeName + "' , ;
> " + "'" + ldDate + "' ) ")
>
>*******************************************************************
>
>I get the following error :
>
>OLE IDispatch exeption code 0 from Microsoft Jet database Engine:
>Syntax error in INSERT INTO statement...
>
>Any help would be appreciated.
>
>Thanks,
>Sergio

Hi,

If you could change your code to:
oCn.Open(lcMDBStr)
cSQL = "INSERT INTO Training ( course , name , date );
             Values ( " + "'" + lcCourse + "' , ;
             " + "'" + lcEmployeeName + "' , ;
             " + "'" + ldDate + "'  ) "
? cSQL
oCn.Execute(cSQL)
and post the value of cSQL, it would be very helpfull. Also datetime literals in MS Access should be written like this: #1/1/2001#. The last character of SQL statement should be ;
Here is a sample:

Insert Into Training (course, name, date) Values ("CS128","Advanced C++",#12/01/2001#);

HTH, Igor
Igor Gelin
Database Developer
Previous
Reply
Map
View

Click here to load this message in the networking platform