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