Page 1 of 1

Error 'There was an error in a part of the date format.'

Posted: Wed May 15, 2013 6:51 am
by Nicolas2121
Hello,

I try to add a field to the database AuditTrail with a script, but I get the error below in the script:

"There was an error in a portion of the date format. [Expression (if known) =]"

Here is my code:

Code: Select all

		/// <summary>
		/// Tries to add LogOP into the database
		/// </summary>
		void Button2_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e)
		{

			if (DB_LogOP.ConnectToDataBase())
			{	
				string DateTime = Globals.Tags.SystemTagDateTime.Value.ToString();
				string CurrentOP = Globals.Tags.SystemTagCurrentUser.Value.ToString()
				// Using try/catch to prevent a crash, should anything go wrong.
				try
				{
					SqlCommand = new SqlCeCommand("INSERT INTO AuditLog (Message, Description, TimeStamp, UserName) VALUES ('Message', 'Description', '"+DateTime+"', '"+CurrentOP+"')", DB_LogOP.SqlConnection);
					SqlCommand.ExecuteNonQuery();
				}
				catch (SqlCeException ex)
				{
					MessageBox.Show(string.Format("{0}",ex.Message),"Erreur d'accès");
				}
				finally
				{
					// Dispose the SqlCommand object.
					SqlCommand.Dispose();
					SqlCommand = null;
					
					// Disconnects from the database.
					DB_LogOP.DisconnectFromDataBase();
				}
			}		
		}
Someone will have an idea of MY error?

Thank you

Re: Error 'There was an error in a part of the date format.'

Posted: Wed May 15, 2013 6:57 am
by Nicolas2121
Ok, I think I found the error. It's running on the T21C panel but not on development PC. Definitely a problem between the date / time format different from the PC.