By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

Very Bad Insert statement--Pls help

exedotsree
P: 8
Hi

Pls help me find out the syntax error in the following stmt...

Expand|Select|Wrap|Line Numbers
  1. Dim insqry As String = "INSERT INTO AssShift(employeeid,departmentid,day" & curdate.Day & ",month,year,lastupdated) VALUES (" & empid & "," & deptid & "," & shid & "," & curdate.Month & "," & curdate.Year & ",#" & Format(Now, shortdateformat) & "#)"
when seen in the addwatch window during run it appears as shown below which seems to be correct...

INSERT INTO AssShift(employeeid,departmentid,day1,month,year,l astupdated) VALUES (249,6,29,3,2008,#3/14/2008#)

when i run this query in MSAccess query,it works fine...
Can any one help me pls....
Mar 14 '08 #1
Share this Question
Share on Google+
4 Replies


debasisdas
Expert 5K+
P: 8,127
How is it that your field names in the database table is dynamic ???
Mar 14 '08 #2

exedotsree
P: 8
How is it that your field names in the database table is dynamic ???
Actually the fieldnames are like day1,day2...day31 for storing shift id for each day in a month.

So, while iterating in the loop for day 1 to day 31, i used it
Mar 14 '08 #3

debasisdas
Expert 5K+
P: 8,127
If using Oracle as database try to use EXECUTE IMMEDIATE for dynamic SQL.
Mar 14 '08 #4

exedotsree
P: 8
If using Oracle as database try to use EXECUTE IMMEDIATE for dynamic SQL.
Hi debasis

I got it solved....the reason is...
there are fieldnames called "month" and "year" which conflicts with keywords.
I altered those fields in the query as [month] and [year] or we can use <tablename>.<fieldname>....

Now its working fine..

Thanks for responding...
Mar 14 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.