Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:50:06+00:00 2026-06-03T02:50:06+00:00

I am getting a Syntax error in Insert INTO statement but I cannot figure

  • 0

I am getting a “Syntax error in Insert INTO statement but I cannot figure out why.

I compared the statement to others I have made that work find, and can find no structural difference. The only difference is that in this one, I am trying to save a DateTime in my MS Access database.

I have my database field in MS Access set for Date/Time with a general format, which is MM/DD/YY HH:MM:SS AM (or PM). I have my DateTime format set the same.

When I set a break point and follow it through, I can see that the DateTime format being passed is correct and matches the general format in MS Access.

I’m sure the problem is right in fromt of me but I’ll be darned if I can see it. Here is my code:

//method to save user input to database
public static void SaveData(ProgramLoginBOL busObject)
{
    try
    {
        String sSQLCommand = "INSERT INTO ProgramLogin ( " +
            "UserName, DateTime) VALUES ('" + busObject.UserName + 
            "','" + busObject.DtDate + "')";

        if (aConnection.State == ConnectionState.Closed)
        {
            aConnection.Open();
        }

        OleDbCommand cmd = aConnection.CreateCommand();
        cmd.CommandText = sSQLCommand;
        // Execute the SQL command
        cmd.ExecuteNonQuery();
        aConnection.Close();

        MessageBox.Show("Data Saved");                 
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        MessageBox.Show("Error! Data was not saved.");
    }
}

As I stated, debugging shows that busObject.DtDate matches the MS Access date/time format

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:50:07+00:00Added an answer on June 3, 2026 at 2:50 am

    One way to solve the problem is to use a Parameterized query instead. Doing this leaves it up to the provider to worry about about types, and you don’t have to worry about delimiting your string values with single quotes (helps with names like O’Donnel) or you date values with #. As a bonus it avoids any SQL injection attacks.

    To do this use ? placeholders for the parameters

       string sSQLCommand = "INSERT INTO ProgramLogin ( " +
                "UserName, DateTime) VALUES (?,?)" 
    

    then later add the parameters

       cmd.Parameters.AddWithValue("?", busObject.UserName);
       cmd.Parameters.AddWithValue("?", busObject.DtDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting syntax error with the following statement REPLACE INTO users (screenname, token,
I'm getting error while converting mysql insert statement into sql server 2008. because limit
Ok, when trying to insert into the database I'm getting this error You have
I'm trying to do: raw_input(Anyone Home?) But I'm getting syntax error! I'm using Python
Here's what I have. I'm getting a syntax error with '])', and I don't
i am using this code <a onclick=javascript:var t=setInterval(GetUpdates(5,ajaxResult),300);>GetUpdates</a> but getting the syntax error
Im getting the error: You have an error in your SQL syntax; check the
I'm getting a syntax error that I don't seem to find an answer to
You have an error in your SQL syntax; check the manual that corresponds to
Can someone run their eyes over this statement? I keep getting a syntax error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.