I'm beginner with SQL and C#. I'm doing a small programm, which allows to connect with an existing database (see code below). The connection and data transfer to SQL Server is done correctly. However, the format of the hour is not the desired. The date and time that I become is shown in the following picture, but I would like to have like this "02.02.2018 14:48". What recommend to me, I have tried 10 different ways but the format remains the same. I'd appreciate your help. :)
namespace SQLConnect
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CmdConnect_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server=LP003;" +
"Trusted_Connection=yes;" +
"database=Margy; " +
"connection timeout=5");
try{
Console.WriteLine("Connecting to MySQL...");
myConnection.Open();
DateTime dateTime = DateTime.Now;
//string dateTime = DateTime.Now.ToString("F");
string sql = "INSERT INTO tblSeeger (PersonalID, DateHour, ProductID, LowLimit, HighLimit, Value, ModifiedValue, machineID, itemID) VALUES ('0001','"+ dateTime + "','x','1,0','1,5','1,2','0,05','0001','123456')";
SqlCommand cmd = new SqlCommand(sql, myConnection);
SqlDataReader rdr = cmd.ExecuteReader();
MessageBox.Show("Well done!");
}
catch (SqlException ex){
MessageBox.Show("You failed!" + ex.Message);
}
myConnection.Close();
Console.WriteLine("Done. ");
}
}
}