D
dookywater
I know this topic has been hit several times in multiple groups but
nobody has complained about an error (that I could find). I am trying
to INSERT multiple rows in an Access DB from a survey (using VB with
ASP.NET). The DB is setup such that there is 3 Columns (ID, Question,
Answer). Typically when one person takes the survey (which is 20
questions) the INSERT statement will add 20 rows to the DB with ID
1-20. Here is some code with my query and error (using fictional data
and only 2 rows to be INSERTED as opposed to 20).
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
.............)
sql=("INSERT INTO Survey (ID, Question, Answer) SELECT ('5',
'question5', 'answer5') UNION ALL SELECT ('6', 'question6', 'answer6')
")
dbcomm=New OleDbCommand(sql,dbconn)
dbconn.Open()
dbcomm.ExecuteNonQuery()
dbconn.Close()
Syntax error (missing operator) in query expression '('5', 'question5',
'answer5') UNION ALL SELECT ('6', 'question6', 'answer6')'.
The interesting thing is that the line with the error on it actually
shows up at this line:
dbcomm.ExecuteNonQuery()
Thus I have tried using the ExecuteReader() method instead to no avail.
Same error.
I've tried using and not using parenthesis in multiple places within
the query and have come up with another error that simply reads Syntax
Error in INSERT INTO statement so I think the way I have them now is
correct.
In the end the fictional data I am trying to INSERT would be more like
' " & a1.SelectedValue & " ', but for testing purposed I'm just keeping
it simple.
Any suggestions on why I might be getting this error would be greatly
appreciated.
nobody has complained about an error (that I could find). I am trying
to INSERT multiple rows in an Access DB from a survey (using VB with
ASP.NET). The DB is setup such that there is 3 Columns (ID, Question,
Answer). Typically when one person takes the survey (which is 20
questions) the INSERT statement will add 20 rows to the DB with ID
1-20. Here is some code with my query and error (using fictional data
and only 2 rows to be INSERTED as opposed to 20).
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
.............)
sql=("INSERT INTO Survey (ID, Question, Answer) SELECT ('5',
'question5', 'answer5') UNION ALL SELECT ('6', 'question6', 'answer6')
")
dbcomm=New OleDbCommand(sql,dbconn)
dbconn.Open()
dbcomm.ExecuteNonQuery()
dbconn.Close()
Syntax error (missing operator) in query expression '('5', 'question5',
'answer5') UNION ALL SELECT ('6', 'question6', 'answer6')'.
The interesting thing is that the line with the error on it actually
shows up at this line:
dbcomm.ExecuteNonQuery()
Thus I have tried using the ExecuteReader() method instead to no avail.
Same error.
I've tried using and not using parenthesis in multiple places within
the query and have come up with another error that simply reads Syntax
Error in INSERT INTO statement so I think the way I have them now is
correct.
In the end the fictional data I am trying to INSERT would be more like
' " & a1.SelectedValue & " ', but for testing purposed I'm just keeping
it simple.
Any suggestions on why I might be getting this error would be greatly
appreciated.