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

  • SEARCH
  • Home
  • 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 7890089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:15:49+00:00 2026-06-03T06:15:49+00:00

I am trying to save a username and a DateTime object to an MS-Access

  • 0

I am trying to save a username and a DateTime object to an MS-Access database but I get a “Syntax error in INSERT INTO statement.” When I debug the program I see that the date is being properly passed. Also, I completely removed the DateTime information and used the insert command with just the username and it save correctly, so it has something to do with the DateTime itself but I don’t know what. Here is the associated code:

//event handler for Begin Program button
private void btnBeginProgram_Click(object sender, EventArgs e)
{
  //assign DateTime object to current computer date/time 
  busObject.DtDate = DateTime.Now;

  //assign input to busObject.UserName property
  busObject.UserName = txtEnterName.Text;   

  //call method to save input data
  busObject.SaveData();           

  this.Close();
}

//properties for variables and objects
public string UserName
{
  get { return userName; }
  set { userName = value; }
}

public DateTime DtDate
{
  get { return dtDate; }
  set { dtDate = value; }
} 

//method to call SaveData method in ProgramLoginDAL class
public void SaveData()
{
  ProgramLoginDAL.SaveData(this);
}

//method to save user input to database
public static void SaveData(ProgramLoginBOL busObject)
{
  try
  {
    OleDbCommand cmd = aConnection.CreateCommand();

    String sSQLCommand = "INSERT INTO ProgramLogin (UserName, DateTime) VALUES (?,?)";

    cmd.Parameters.AddWithValue("?", busObject.UserName);
    cmd.Parameters.AddWithValue("?", busObject.DtDate);

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

    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.");
  }
}
  • 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-03T06:15:50+00:00Added an answer on June 3, 2026 at 6:15 am

    Try placing brackets around your field name. It’s probably a keyword:

    String sSQLCommand = "INSERT INTO ProgramLogin (UserName, [DateTime]) VALUES (?,?)";
    

    For DateTime, you might have to specify the data type:

    sSQLCommand .Parameters.Add(
      new OleDbParameter("?", OleDbType.Date) { Value = 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 a Syntax error in Insert INTO statement but I cannot figure
For a few days, I have been trying to get the username to save
I'm trying to get a JSON object like: { username: clelio, name: Clelio de
Im trying to save a simple script in netbeans to htdocs, but i only
When trying to save the database using boost serialization, I encounter the segfault that
I am trying to save a custom object as a user setting in a
I'm trying to save some UserControl-Infos into a List like this: List<UserControlDetails> myList; public
I'm trying to save the returned data from HTTP request into a variable. The
I'm trying to check username and password by using a For Each Statement. If
Trying to perform a nested object form. The page loads with no errors, but

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.