Solved

Syntax Error in INSERT INTO Statement

Posted on 2004-10-26
236 Views
Last Modified: 2010-04-15
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
Question by:ptslv
    2 Comments
     
    LVL 15

    Accepted Solution

    by:
    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
     

    Author Comment

    by:ptslv
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now