[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Syntax Error in INSERT INTO Statement

I am trying to insert data into an Access database using C# in a Windows App.  I keep getting a syntax error on this  sql statement telling me a ';' is expected at the end of the statement.  I put extra ; in and get the same error.  All other surrounding code has the proper ';'.  

string strSQLSelect1 = "INSERT INTO [Import] ([timeStamp], DocumentName, DocumentType, TransactionType,TANUM)  " +
      "VALUES( " + @timeStamp, @DocumentName, @DocumentType, @TransactionType, @TANUM +" )";

ptslv
0
ptslv
Asked:
ptslv
1 Solution
 
SRigneyCommented:
Access Queries themselves expect to end in a semicolon, and you need to fill in the values for you query.

Try this:

string strSQLSelect1 =
  String.Format("INSERT INTO [Import] ([timeStamp], DocumentName, DocumentType, TransactionType,TANUM) VALUES( {0}, {1}, {2}, {3}, {4}, {5});", timeStamp, DocumentName, DocumentType, TransactionType, TANUM );

Make sure that you are using the correct variables that hold to values for
timeStamp, DocumentName, DocumentType, TransactionType, TANUM
0
 
ptslvAuthor Commented:
Thanks, SRigney.  But I already trashed this version because it worked without the Insert Into query.  I was having other problems that prompted me to go this route.  However, since you responded before I cancelled the question, I will give you the points.  If you want more, just see my next question!  ;-)

ptslv
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now